提交 65cf4260 authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 138: the trace output of Statement.execute(String, int) and executeUpdate was incorrect.

上级 5fb0c18e
...@@ -576,9 +576,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -576,9 +576,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public void setRef(int parameterIndex, Ref x) throws SQLException { public void setRef(int parameterIndex, Ref x) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("setRef("+parameterIndex+", x);");
debugCode("setRef("+parameterIndex+", x);");
}
throw Message.getUnsupportedException("ref"); throw Message.getUnsupportedException("ref");
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -663,9 +661,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -663,9 +661,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("setUnicodeStream("+parameterIndex+", x, "+length+");");
debugCode("setUnicodeStream("+parameterIndex+", x, "+length+");");
}
throw Message.getUnsupportedException("unicodeStream"); throw Message.getUnsupportedException("unicodeStream");
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -795,9 +791,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -795,9 +791,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public void setArray(int parameterIndex, Array x) throws SQLException { public void setArray(int parameterIndex, Array x) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("setArray("+parameterIndex+", x);");
debugCode("setArray("+parameterIndex+", x);");
}
throw Message.getUnsupportedException("setArray"); throw Message.getUnsupportedException("setArray");
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -978,9 +972,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -978,9 +972,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public void setURL(int parameterIndex, URL x) throws SQLException { public void setURL(int parameterIndex, URL x) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("setURL("+parameterIndex+", x);");
debugCode("setURL("+parameterIndex+", x);");
}
throw Message.getUnsupportedException("url"); throw Message.getUnsupportedException("url");
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1127,9 +1119,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -1127,9 +1119,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");");
debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");");
}
throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1144,9 +1134,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -1144,9 +1134,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("executeUpdate(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");");
debugCode("executeUpdate(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");");
}
throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1160,9 +1148,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -1160,9 +1148,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public int executeUpdate(String sql, String[] columnNames) throws SQLException { public int executeUpdate(String sql, String[] columnNames) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("executeUpdate(" + quote(sql) + ", " + quoteArray(columnNames) + ");");
debugCode("executeUpdate(" + quote(sql) + ", " + quoteArray(columnNames) + ");");
}
throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1176,9 +1162,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -1176,9 +1162,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("execute(" + quote(sql) + ", " + autoGeneratedKeys + ");");
debugCode("execute(" + quote(sql) + ", " + autoGeneratedKeys + ");");
}
throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1192,9 +1176,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -1192,9 +1176,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public boolean execute(String sql, int[] columnIndexes) throws SQLException { public boolean execute(String sql, int[] columnIndexes) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("execute(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");");
debugCode("execute(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");");
}
throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -1208,9 +1190,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat ...@@ -1208,9 +1190,7 @@ public class JdbcPreparedStatement extends JdbcStatement implements PreparedStat
*/ */
public boolean execute(String sql, String[] columnNames) throws SQLException { public boolean execute(String sql, String[] columnNames) throws SQLException {
try { try {
if (isDebugEnabled()) { debugCode("execute(" + quote(sql) + ", " + quoteArray(columnNames) + ");");
debugCode("execute(" + quote(sql) + ", " + quoteArray(columnNames) + ");");
}
throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT); throw Message.getSQLException(ErrorCode.METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
......
...@@ -106,25 +106,29 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -106,25 +106,29 @@ public class JdbcStatement extends TraceObject implements Statement {
public int executeUpdate(String sql) throws SQLException { public int executeUpdate(String sql) throws SQLException {
try { try {
debugCodeCall("executeUpdate", sql); debugCodeCall("executeUpdate", sql);
checkClosedForWrite(); return executeUpdateInternal(sql);
closeOldResultSet();
sql = conn.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
synchronized (session) {
setExecutingStatement(command);
try {
updateCount = command.executeUpdate();
} finally {
setExecutingStatement(null);
}
}
command.close();
return updateCount;
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
} }
private int executeUpdateInternal(String sql) throws SQLException {
checkClosedForWrite();
closeOldResultSet();
sql = conn.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
synchronized (session) {
setExecutingStatement(command);
try {
updateCount = command.executeUpdate();
} finally {
setExecutingStatement(null);
}
}
command.close();
return updateCount;
}
/** /**
* Executes an arbitrary statement. If another result set exists for this * Executes an arbitrary statement. If another result set exists for this
* statement, this will be closed (even if this statement fails). * statement, this will be closed (even if this statement fails).
...@@ -139,39 +143,41 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -139,39 +143,41 @@ public class JdbcStatement extends TraceObject implements Statement {
*/ */
public boolean execute(String sql) throws SQLException { public boolean execute(String sql) throws SQLException {
try { try {
int id = getNextId(TraceObject.RESULT_SET); debugCodeCall("execute", sql);
if (isDebugEnabled()) { return executeInternal(sql);
debugCodeCall("execute", sql);
}
checkClosedForWrite();
closeOldResultSet();
sql = conn.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
boolean returnsResultSet;
synchronized (session) {
setExecutingStatement(command);
try {
if (command.isQuery()) {
returnsResultSet = true;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
ResultInterface result = command.executeQuery(maxRows, scrollable);
resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
} else {
returnsResultSet = false;
updateCount = command.executeUpdate();
}
} finally {
setExecutingStatement(null);
}
}
command.close();
return returnsResultSet;
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
} }
private boolean executeInternal(String sql) throws SQLException {
int id = getNextId(TraceObject.RESULT_SET);
checkClosedForWrite();
closeOldResultSet();
sql = conn.translateSQL(sql, escapeProcessing);
CommandInterface command = conn.prepareCommand(sql, fetchSize);
boolean returnsResultSet;
synchronized (session) {
setExecutingStatement(command);
try {
if (command.isQuery()) {
returnsResultSet = true;
boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
ResultInterface result = command.executeQuery(maxRows, scrollable);
resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
} else {
returnsResultSet = false;
updateCount = command.executeUpdate();
}
} finally {
setExecutingStatement(null);
}
}
command.close();
return returnsResultSet;
}
/** /**
* Returns the last result set produces by this statement. * Returns the last result set produces by this statement.
* *
...@@ -610,7 +616,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -610,7 +616,7 @@ public class JdbcStatement extends TraceObject implements Statement {
for (int i = 0; i < batchCommands.size(); i++) { for (int i = 0; i < batchCommands.size(); i++) {
String sql = batchCommands.get(i); String sql = batchCommands.get(i);
try { try {
result[i] = executeUpdate(sql); result[i] = executeUpdateInternal(sql);
} catch (SQLException e) { } catch (SQLException e) {
logAndConvert(e); logAndConvert(e);
//## Java 1.4 begin ## //## Java 1.4 begin ##
...@@ -698,7 +704,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -698,7 +704,7 @@ public class JdbcStatement extends TraceObject implements Statement {
if (isDebugEnabled()) { if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");"); debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");");
} }
return executeUpdate(sql); return executeUpdateInternal(sql);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -720,7 +726,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -720,7 +726,7 @@ public class JdbcStatement extends TraceObject implements Statement {
if (isDebugEnabled()) { if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+quoteIntArray(columnIndexes)+");"); debugCode("executeUpdate("+quote(sql)+", "+quoteIntArray(columnIndexes)+");");
} }
return executeUpdate(sql); return executeUpdateInternal(sql);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -742,7 +748,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -742,7 +748,7 @@ public class JdbcStatement extends TraceObject implements Statement {
if (isDebugEnabled()) { if (isDebugEnabled()) {
debugCode("executeUpdate("+quote(sql)+", "+quoteArray(columnNames)+");"); debugCode("executeUpdate("+quote(sql)+", "+quoteArray(columnNames)+");");
} }
return executeUpdate(sql); return executeUpdateInternal(sql);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -764,7 +770,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -764,7 +770,7 @@ public class JdbcStatement extends TraceObject implements Statement {
if (isDebugEnabled()) { if (isDebugEnabled()) {
debugCode("execute("+quote(sql)+", "+autoGeneratedKeys+");"); debugCode("execute("+quote(sql)+", "+autoGeneratedKeys+");");
} }
return execute(sql); return executeInternal(sql);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -786,7 +792,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -786,7 +792,7 @@ public class JdbcStatement extends TraceObject implements Statement {
if (isDebugEnabled()) { if (isDebugEnabled()) {
debugCode("execute("+quote(sql)+", "+quoteIntArray(columnIndexes)+");"); debugCode("execute("+quote(sql)+", "+quoteIntArray(columnIndexes)+");");
} }
return execute(sql); return executeInternal(sql);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -808,7 +814,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -808,7 +814,7 @@ public class JdbcStatement extends TraceObject implements Statement {
if (isDebugEnabled()) { if (isDebugEnabled()) {
debugCode("execute("+quote(sql)+", "+quoteArray(columnNames)+");"); debugCode("execute("+quote(sql)+", "+quoteArray(columnNames)+");");
} }
return execute(sql); return executeInternal(sql);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论