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

PreparedStatement.toString() now includes the parameter values in a human readable format.

上级 d3337916
......@@ -153,7 +153,7 @@ public abstract class Expression {
/**
* Is the value of a parameter set.
*
* @return if it is set
* @return true if set
*/
public boolean isValueSet() {
return false;
......
......@@ -35,6 +35,13 @@ public interface ParameterInterface {
*/
void checkSet();
/**
* Is the value of a parameter set.
*
* @return true if set
*/
boolean isValueSet();
/**
* Get the expected data type of the parameter if no value is set, or the
* data type of the value if one is set.
......
......@@ -46,6 +46,10 @@ public class ParameterRemote implements ParameterInterface {
}
}
public boolean isValueSet() {
return value != null;
}
public int getType() {
return value == null ? dataType : value.getType();
}
......
......@@ -12,6 +12,7 @@ import org.h2.constant.SysProperties;
import org.h2.expression.ParameterInterface;
import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
import org.h2.value.Value;
/**
* This class represents a trace module.
......@@ -216,13 +217,24 @@ public class Trace {
if (parameters.size() == 0) {
return "";
}
StatementBuilder buff = new StatementBuilder(" {");
StatementBuilder buff = new StatementBuilder();
int i = 0;
boolean params = false;
for (ParameterInterface p : parameters) {
buff.appendExceptFirst(", ");
buff.append(++i).append(": ").append(p.getParamValue().getTraceSQL());
if (p.isValueSet()) {
if (!params) {
buff.append(" {");
params = true;
}
buff.appendExceptFirst(", ");
Value v = p.getParamValue();
buff.append(++i).append(": ").append(v.getTraceSQL());
}
}
return buff.append('}').toString();
if (params) {
buff.append('}');
}
return buff.toString();
}
/**
......
......@@ -42,7 +42,6 @@ public class TestPreparedStatement extends TestBase {
}
public void test() throws Exception {
deleteDb("preparedStatement");
Connection conn = getConnection("preparedStatement");
testToString(conn);
......@@ -84,7 +83,7 @@ public class TestPreparedStatement extends TestBase {
PreparedStatement prep = conn.prepareStatement("call 1");
assertTrue(prep.toString().endsWith(": call 1"));
prep = conn.prepareStatement("call ?");
assertTrue(prep.toString().endsWith(": call ? {1: NULL}"));
assertTrue(prep.toString().endsWith(": call ?"));
prep.setString(1, "Hello World");
assertTrue(prep.toString().endsWith(": call ? {1: 'Hello World'}"));
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论