[#1177] Add SQL Console module to jOOQ - Fixed parameters display in logger.

This commit is contained in:
Chrriis 2012-02-24 17:10:13 +00:00
parent c759e1b697
commit f8fc5e8bb9
2 changed files with 8 additions and 17 deletions

View File

@ -78,7 +78,6 @@ public class SqlQueryDebuggerExecuteListener extends DefaultExecuteListener {
}
aggregatedPreparationDuration += System.currentTimeMillis() - startPreparationTime;
PreparedStatement statement = ctx.statement();
// TODO: How to wrap CallableStatement ?
// Wrapping it with UsageTrackingPreparedStatement will cause
// ClassCastExceptions in jOOQ. Maybe there is a design issue?
@ -129,10 +128,6 @@ public class SqlQueryDebuggerExecuteListener extends DefaultExecuteListener {
}
ResultSet resultSet = ctx.resultSet();
String[] sql = ctx.batchSQL();
// Temporary code to avoid bug of BatchSingle not filling the batchSQL array.
if(sql.length == 1 && sql[0] == null) {
sql = new String[] {ctx.sql()};
}
SqlQueryType sqlQueryType = getSqlQueryType(sql[0]);
if(sql.length == 1) {
PreparedStatement statement = ctx.statement();

View File

@ -294,7 +294,7 @@ public class UsageTrackingPreparedStatement implements PreparedStatement {
@Override
public void setNString(int parameterIndex, String x) throws SQLException {
stmt.setNString(parameterIndex, x);
logValue(parameterIndex, x == null? null: '"' + x + '"');
logValue(parameterIndex, x == null? null: '\'' + x.replace("'", "''") + '\'');
}
@Override
@ -354,7 +354,7 @@ public class UsageTrackingPreparedStatement implements PreparedStatement {
@Override
public void setString(int parameterIndex, String x) throws SQLException {
stmt.setString(parameterIndex, x);
logValue(parameterIndex, x == null? null: '"' + x + '"');
logValue(parameterIndex, x == null? null: '\'' + x.replace("'", "''") + '\'');
}
@Override
@ -624,7 +624,6 @@ public class UsageTrackingPreparedStatement implements PreparedStatement {
return stmt;
}
private boolean isNew = true;
private StringBuilder sb = new StringBuilder();
private List<String> paramList = new ArrayList<String>();
@ -641,25 +640,22 @@ public class UsageTrackingPreparedStatement implements PreparedStatement {
}
}
sb.append("]");
isNew = true;
}
private void logValue(int parameterIndex, Object o) {
isNew = false;
int missingLength = parameterIndex + 1 - paramList.size();
// parameters in SQL are 1-based
int missingLength = parameterIndex - paramList.size();
for(int i=0; i<missingLength; i++) {
paramList.add(null);
}
paramList.set(parameterIndex, String.valueOf(o));
paramList.set(parameterIndex-1, String.valueOf(o));
}
public String getParameterDescription() {
if(isNew) {
if(paramList.isEmpty() && sb.length() == 0) {
return null;
}
// commitParameterDescription();
if(paramList.isEmpty() && sb.length() == 0) {
return null;
}
commitParameterDescription();
return sb.toString();
}