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

--no commit message

--no commit message
上级 7b41b960
...@@ -17,9 +17,7 @@ import org.h2.expression.Parameter; ...@@ -17,9 +17,7 @@ import org.h2.expression.Parameter;
import org.h2.message.Message; import org.h2.message.Message;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.util.ObjectArray; import org.h2.util.ObjectArray;
import org.h2.util.StringUtils;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueLob;
/** /**
* A prepared statement. * A prepared statement.
...@@ -320,35 +318,7 @@ public abstract class Prepared { ...@@ -320,35 +318,7 @@ public abstract class Prepared {
buff.append(": "); buff.append(": ");
Expression e = (Expression) parameters.get(i); Expression e = (Expression) parameters.get(i);
Value v = e.getValue(session); Value v = e.getValue(session);
try { buff.append(v.getTraceSQL());
if (v.getPrecision() > SysProperties.MAX_TRACE_DATA_LENGTH) {
if (v.getType() == Value.CLOB) {
ValueLob lob = (ValueLob) v;
buff.append("SPACE(");
buff.append(lob.getPrecision());
buff.append(")");
buff.append("/* ");
buff.append(lob.getObjectId());
buff.append("*/");
} else if (v.getType() == Value.BLOB) {
ValueLob lob = (ValueLob) v;
buff.append("CAST(REPEAT('00', ");
buff.append(lob.getPrecision());
buff.append(") AS BINARY)");
buff.append("/* ");
buff.append(lob.getObjectId());
buff.append("*/");
} else {
buff.append(v.getSQL());
}
} else {
buff.append(v.getSQL());
}
} catch (Exception t) {
buff.append("? /*");
buff.append(StringUtils.quoteJavaString(t.getMessage()));
buff.append("*/");
}
} }
buff.append("}"); buff.append("}");
params = buff.toString(); params = buff.toString();
......
...@@ -289,6 +289,6 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -289,6 +289,6 @@ public class JdbcArray extends TraceObject implements Array {
* INTERNAL * INTERNAL
*/ */
public String toString() { public String toString() {
return getTraceObjectName() + ": " + value.getSQL(); return getTraceObjectName() + ": " + value.getTraceSQL();
} }
} }
...@@ -292,7 +292,7 @@ public class JdbcBlob extends TraceObject implements Blob { ...@@ -292,7 +292,7 @@ public class JdbcBlob extends TraceObject implements Blob {
* INTERNAL * INTERNAL
*/ */
public String toString() { public String toString() {
return getTraceObjectName() + ": " + value.getSQL(); return getTraceObjectName() + ": " + value.getTraceSQL();
} }
} }
...@@ -232,7 +232,7 @@ public class JdbcClob extends TraceObject implements Clob ...@@ -232,7 +232,7 @@ public class JdbcClob extends TraceObject implements Clob
* INTERNAL * INTERNAL
*/ */
public String toString() { public String toString() {
return getTraceObjectName() + ": " + value.getSQL(); return getTraceObjectName() + ": " + value.getTraceSQL();
} }
} }
...@@ -170,7 +170,7 @@ public class ResultRemote implements ResultInterface { ...@@ -170,7 +170,7 @@ public class ResultRemote implements ResultInterface {
try { try {
v.close(); v.close();
} catch (SQLException e) { } catch (SQLException e) {
trace.error("delete lob " + v.getSQL(), e); trace.error("delete lob " + v.getTraceSQL(), e);
} }
} }
lobValues = null; lobValues = null;
......
...@@ -100,7 +100,7 @@ public class Row extends Record implements SearchRow { ...@@ -100,7 +100,7 @@ public class Row extends Record implements SearchRow {
if (i > 0) { if (i > 0) {
buff.append(", "); buff.append(", ");
} }
buff.append(data[i].getSQL()); buff.append(data[i].getTraceSQL());
} }
buff.append(')'); buff.append(')');
return buff.toString(); return buff.toString();
......
...@@ -51,7 +51,7 @@ public class SimpleRowValue implements SearchRow { ...@@ -51,7 +51,7 @@ public class SimpleRowValue implements SearchRow {
} }
public String toString() { public String toString() {
return "( /* " + pos + " */ " + data.getSQL() + " )"; return "( /* " + pos + " */ " + data.getTraceSQL() + " )";
} }
} }
...@@ -292,7 +292,11 @@ public class Column { ...@@ -292,7 +292,11 @@ public class Column {
value = value.convertScale(mode.convertOnlyToSmallerScale, scale); value = value.convertScale(mode.convertOnlyToSmallerScale, scale);
if (precision > 0) { if (precision > 0) {
if (!value.checkPrecision(precision)) { if (!value.checkPrecision(precision)) {
throw Message.getSQLException(ErrorCode.VALUE_TOO_LONG_2, new String[]{name, value.getSQL()}); String s = value.getTraceSQL();
if (s.length() > 127) {
s = s.substring(0, 128) + "...";
}
throw Message.getSQLException(ErrorCode.VALUE_TOO_LONG_2, new String[]{name, s});
} }
} }
updateSequenceIfRequired(session, value); updateSequenceIfRequired(session, value);
......
...@@ -967,9 +967,19 @@ public abstract class Value { ...@@ -967,9 +967,19 @@ public abstract class Value {
public boolean checkPrecision(long precision) { public boolean checkPrecision(long precision) {
return getPrecision() <= precision; return getPrecision() <= precision;
} }
/**
* Get a medium size SQL expression for debugging or tracing. If the precision is
* too large, only a subset of the value is returned.
*
* @return the SQL expression
*/
public String getTraceSQL() {
return getSQL();
}
public String toString() { public String toString() {
return getSQL(); return getTraceSQL();
} }
} }
...@@ -114,7 +114,19 @@ public class ValueArray extends Value { ...@@ -114,7 +114,19 @@ public class ValueArray extends Value {
buff.append(')'); buff.append(')');
return buff.toString(); return buff.toString();
} }
public String getTraceSQL() {
StringBuffer buff = new StringBuffer();
buff.append('(');
for (int i = 0; i < values.length; i++) {
if (i > 0) {
buff.append(", ");
}
buff.append(values[i].getTraceSQL());
}
buff.append(')');
return buff.toString();
}
public int getDisplaySize() { public int getDisplaySize() {
long size = 0; long size = 0;
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
......
...@@ -653,11 +653,26 @@ public class ValueLob extends Value { ...@@ -653,11 +653,26 @@ public class ValueLob extends Value {
} }
} }
public String toString() { public String getTraceSQL() {
if (small == null) { if (getPrecision() <= SysProperties.MAX_TRACE_DATA_LENGTH) {
return getClass().getName() + " file: " + fileName + " type: " + type + " precision: " + precision; return getSQL();
} }
return getSQL(); StringBuffer buff = new StringBuffer();
if (type == Value.CLOB) {
buff.append("SPACE(");
buff.append(getPrecision());
} else {
buff.append("CAST(REPEAT('00', ");
buff.append(getPrecision());
buff.append(") AS BINARY");
}
if (small != null) {
buff.append(" /* ");
buff.append(fileName);
buff.append(" */");
}
buff.append(")");
return buff.toString();
} }
/** /**
......
...@@ -28,7 +28,7 @@ abstract class ValueStringBase extends Value { ...@@ -28,7 +28,7 @@ abstract class ValueStringBase extends Value {
public String getSQL() { public String getSQL() {
return StringUtils.quoteStringSQL(value); return StringUtils.quoteStringSQL(value);
} }
public String getString() { public String getString() {
return value; return value;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论