From cf570d55bf09d7aa7af196fafe90db2200002aa5 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 14 Nov 2008 23:52:24 +0000 Subject: Log SQL bind variable values. --- .../repo/jdbc/LoggingPreparedStatement.java | 116 +++++++++++++++------ 1 file changed, 82 insertions(+), 34 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/LoggingPreparedStatement.java b/src/main/java/com/amazon/carbonado/repo/jdbc/LoggingPreparedStatement.java index 9406005..4d57aac 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/LoggingPreparedStatement.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/LoggingPreparedStatement.java @@ -19,6 +19,7 @@ package com.amazon.carbonado.repo.jdbc; import java.math.BigDecimal; +import java.math.BigInteger; import java.util.Calendar; import java.sql.*; @@ -32,116 +33,150 @@ import org.apache.commons.logging.Log; class LoggingPreparedStatement extends LoggingStatement implements PreparedStatement { protected final String mSQL; + private Object[] mParams; + private BigInteger mSetParams = BigInteger.ZERO; + LoggingPreparedStatement(Log log, Connection con, PreparedStatement ps, String sql) { super(log, con, ps); mSQL = sql; } public ResultSet executeQuery() throws SQLException { - mLog.debug(mSQL); + logStatement(); return ps().executeQuery(); } public int executeUpdate() throws SQLException { - mLog.debug(mSQL); + logStatement(); return ps().executeUpdate(); } public boolean execute() throws SQLException { - mLog.debug(mSQL); + logStatement(); return ps().execute(); } + private void logStatement() { + String statement = mSQL; + + Object[] params; + BigInteger setParams; + if ((params = mParams) != null && (setParams = mSetParams) != BigInteger.ZERO) { + int length = setParams.bitLength(); + StringBuilder b = new StringBuilder(statement.length() + length * 10); + b.append(statement); + b.append(" -- "); + boolean any = false; + for (int i=0; i