提交 fe62b1dc authored 作者: Thomas Mueller's avatar Thomas Mueller

The H2 Console now abbreviates large texts in results.

上级 c3fc6e3e
...@@ -18,7 +18,8 @@ Change Log ...@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Multiple UNION queries could not be used in derived tables. <ul><li>The H2 Console now abbreviates large texts in results.
</li><li>Multiple UNION queries could not be used in derived tables.
</li><li>Linked tables can now be read-only. </li><li>Linked tables can now be read-only.
</li><li>Temporary linked tables are now supported. </li><li>Temporary linked tables are now supported.
</li><li>The optimization for IN(...) is now enabled by default. Use -Dh2.optimizeInJoin=false to disable it. </li><li>The optimization for IN(...) is now enabled by default. Use -Dh2.optimizeInJoin=false to disable it.
......
...@@ -210,6 +210,12 @@ public class SysProperties { ...@@ -210,6 +210,12 @@ public class SysProperties {
*/ */
public static final int EMERGENCY_SPACE_MIN = getIntSetting("h2.emergencySpaceMin", 64 * 1024); public static final int EMERGENCY_SPACE_MIN = getIntSetting("h2.emergencySpaceMin", 64 * 1024);
/**
* System property <code>h2.largeResultBufferSize</code> (default: 4096).<br />
* Buffer size for large result sets. Set this value to 0 to disable the buffer.
*/
public static final int LARGE_RESULT_BUFFER_SIZE = getIntSetting("h2.largeResultBufferSize", 4 * 1024);
/** /**
* System property <code>h2.lobCloseBetweenReads</code> (default: false).<br /> * System property <code>h2.lobCloseBetweenReads</code> (default: false).<br />
* Close LOB files between read operations. * Close LOB files between read operations.
...@@ -463,10 +469,10 @@ public class SysProperties { ...@@ -463,10 +469,10 @@ public class SysProperties {
public static final boolean TRACE_IO = getBooleanSetting("h2.traceIO", false); public static final boolean TRACE_IO = getBooleanSetting("h2.traceIO", false);
/** /**
* System property <code>h2.largeResultBufferSize</code> (default: 4096).<br /> * System property <code>h2.webMaxValueLength</code> (default: 10000).<br />
* Buffer size for large result sets. Set this value to 0 to disable the buffer. * The H2 Console will abbreviate result values larger than this size.
*/ */
public static final int LARGE_RESULT_BUFFER_SIZE = getIntSetting("h2.largeResultBufferSize", 4 * 1024); public static final int WEB_MAX_VALUE_LENGTH = getIntSetting("h2.webMaxValueLength", 10000);
/** /**
* System property <code>h2.collatorCacheSize</code> (default: 10000).<br /> * System property <code>h2.collatorCacheSize</code> (default: 10000).<br />
......
...@@ -48,6 +48,7 @@ import java.util.Map.Entry; ...@@ -48,6 +48,7 @@ import java.util.Map.Entry;
import org.h2.api.DatabaseEventListener; import org.h2.api.DatabaseEventListener;
import org.h2.bnf.Bnf; import org.h2.bnf.Bnf;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.jdbc.JdbcSQLException; import org.h2.jdbc.JdbcSQLException;
import org.h2.message.Message; import org.h2.message.Message;
...@@ -1373,7 +1374,7 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -1373,7 +1374,7 @@ class WebThread extends Thread implements DatabaseEventListener {
} }
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) { for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
String x = attributes.getProperty("r" + row + "c" + (i + 1)); String x = attributes.getProperty("r" + row + "c" + (i + 1));
rs.updateString(i + 1, unescapeData(x)); unescapeData(x, rs, i + 1);
} }
if (insert) { if (insert) {
rs.insertRow(); rs.insertRow();
...@@ -1950,7 +1951,7 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -1950,7 +1951,7 @@ class WebThread extends Thread implements DatabaseEventListener {
buff.append(PageParser.escapeHtml(meta.getColumnLabel(i + 1))); buff.append(PageParser.escapeHtml(meta.getColumnLabel(i + 1)));
buff.append("</td>"); buff.append("</td>");
buff.append("<td>"); buff.append("<td>");
buff.append(escapeData(rs.getString(i + 1))); buff.append(escapeData(rs, i + 1));
buff.append("</td></tr>"); buff.append("</td></tr>");
} }
} }
...@@ -1986,7 +1987,7 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -1986,7 +1987,7 @@ class WebThread extends Thread implements DatabaseEventListener {
} }
for (int i = 0; i < columns; i++) { for (int i = 0; i < columns; i++) {
buff.append("<td>"); buff.append("<td>");
buff.append(escapeData(rs.getString(i + 1))); buff.append(escapeData(rs, i + 1));
buff.append("</td>"); buff.append("</td>");
} }
buff.append("</tr>"); buff.append("</tr>");
...@@ -2059,24 +2060,30 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -2059,24 +2060,30 @@ class WebThread extends Thread implements DatabaseEventListener {
return "index.do"; return "index.do";
} }
private String escapeData(String d) { private String escapeData(ResultSet rs, int columnIndex) throws SQLException {
String d = rs.getString(columnIndex);
if (d == null) { if (d == null) {
return "<i>null</i>"; return "<i>null</i>";
} else if (d.startsWith("null")) { } else if (d.length() > SysProperties.WEB_MAX_VALUE_LENGTH) {
return "<div style='display: none'>=</div>" + PageParser.escapeHtml(d); return "<div style='display: none'>=+</div>" +
PageParser.escapeHtml(d.substring(0, 100) + "... (" + d.length() + ")");
} else if (d.equals("null") || d.startsWith("= ") || d.startsWith("=+")) {
return "<div style='display: none'>= </div>" + PageParser.escapeHtml(d);
} }
return PageParser.escapeHtml(d); return PageParser.escapeHtml(d);
} }
private String unescapeData(String d) { private void unescapeData(String d, ResultSet rs, int columnIndex) throws SQLException {
if (d.endsWith("null")) { if (d.equals("null")) {
if (d.equals("null")) { rs.updateNull(columnIndex);
return null; } else if (d.startsWith("=+")) {
} else if (d.startsWith("=")) { // don't update
return d.substring(1); } else if (d.startsWith("= ")) {
} d = d.substring(2);
rs.updateString(columnIndex, d);
} else {
rs.updateString(columnIndex, d);
} }
return d;
} }
private String settingRemove() { private String settingRemove() {
......
...@@ -275,9 +275,7 @@ java org.h2.test.TestAll timer ...@@ -275,9 +275,7 @@ java org.h2.test.TestAll timer
main methods for the tests and make that work main methods for the tests and make that work
H2 Console: don't display very large blobs; instead show first view bytes and length TestMVCC:
MVCC:
Concurrent update in table test: another transaction has updated or Concurrent update in table test: another transaction has updated or
deleted the same row when exactly does it occur in other databases deleted the same row when exactly does it occur in other databases
(PostgreSQL, Oracle)? (PostgreSQL, Oracle)?
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论