=== modified file 'CHANGES' --- CHANGES 2009-12-14 15:43:46 +0000 +++ CHANGES 2009-12-18 19:44:05 +0000 @@ -3,6 +3,9 @@ mm-dd-yy - Version 5.1.11 (not yet released) + - Fix for BUG#49745 - deleteRow() for updatable result sets can cause full table scan because escaped hex + values are used for primary key identifiers. + - Fix for BUG#49607 - Provide Connection context in ExceptionInterceptor. - Fix for BUG#48605 - Ping leaves closed connections in liveConnections, causing subsequent Exceptions when === modified file 'src/com/mysql/jdbc/UpdatableResultSet.java' --- src/com/mysql/jdbc/UpdatableResultSet.java 2009-08-20 21:27:24 +0000 +++ src/com/mysql/jdbc/UpdatableResultSet.java 2009-12-18 18:49:23 +0000 @@ -26,6 +26,7 @@ import java.math.BigDecimal; import java.sql.SQLException; +import java.sql.Types; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -95,6 +96,7 @@ private boolean populateInserterWithDefaultValues = false; private Map databasesUsedToTablesUsed = null; + /** * Creates a new ResultSet object. @@ -483,15 +485,15 @@ if (numKeys == 1) { int index = ((Integer) this.primaryKeyIndicies.get(0)) .intValue(); - byte[] currentVal = this.thisRow.getColumnValue(index); - this.deleter.setBytes(1, currentVal); + this.setParamValue(this.deleter, 1, this.thisRow, + index, this.fields[index].getSQLType()); } else { for (int i = 0; i < numKeys; i++) { int index = ((Integer) this.primaryKeyIndicies.get(i)) .intValue(); - byte[] currentVal = this.thisRow.getColumnValue(index); - - this.deleter.setBytes(i + 1, currentVal); + this.setParamValue(this.deleter, i + 1, this.thisRow, + index, this.fields[index].getSQLType()); + } } @@ -502,6 +504,59 @@ previous(); } + + private synchronized void setParamValue(PreparedStatement ps, int psIdx, + ResultSetRow row, int rsIdx, int sqlType) throws SQLException { + + byte[] val = row.getColumnValue(rsIdx); + if(val == null){ + ps.setNull(psIdx, Types.NULL); + return; + } + switch (sqlType) { + case Types.NULL: + ps.setNull(psIdx, Types.NULL); + break; + case Types.TINYINT: + case Types.SMALLINT: + case Types.INTEGER: + ps.setInt(psIdx, row.getInt(rsIdx)); + break; + case Types.BIGINT: + ps.setLong(psIdx, row.getLong(rsIdx)); + break; + case Types.CHAR: + case Types.VARCHAR: + case Types.LONGVARCHAR: + case Types.DECIMAL: + case Types.NUMERIC: + ps.setString(psIdx, row.getString(rsIdx, this.charEncoding, this.connection)); + break; + case Types.DATE: + ps.setDate(psIdx, row.getDateFast(rsIdx, this.connection, this, this.fastDateCal), this.fastDateCal); + break; + case Types.TIMESTAMP: + ps.setTimestamp(psIdx, row.getTimestampFast(rsIdx, this.fastDateCal, this.defaultTimeZone, false, this.connection, this)); + break; + case Types.TIME: + ps.setTime(psIdx, row.getTimeFast(rsIdx, this.fastDateCal, this.defaultTimeZone, false, this.connection, this)); + break; + case Types.FLOAT: + case Types.DOUBLE: + case Types.REAL: + case Types.BOOLEAN: + ps.setBytesNoEscapeNoQuotes(psIdx, val); + break; + /* default, but also explicitly for following types: + case Types.BINARY: + case Types.BLOB: + */ + default: + ps.setBytes(psIdx, val); + break; + } + + } private synchronized void extractDefaultValues() throws SQLException { java.sql.DatabaseMetaData dbmd = this.connection.getMetaData(); @@ -713,7 +768,7 @@ fqcnBuf.append(quotedId); String qualifiedColumnName = fqcnBuf.toString(); - + if (this.fields[i].isPrimaryKey()) { this.primaryKeyIndicies.add(Constants.integerValueOf(i)); @@ -1504,19 +1559,13 @@ if (numKeys == 1) { int index = ((Integer) this.primaryKeyIndicies.get(0)).intValue(); - byte[] keyData = (byte[]) this.thisRow.getColumnValue(index); - this.updater.setBytes(numFields + 1, keyData, false, false); + this.setParamValue(this.updater, numFields + 1, this.thisRow, index , + this.fields[index].getSQLType()); } else { for (int i = 0; i < numKeys; i++) { - byte[] currentVal = (byte[]) this.thisRow.getColumnValue(((Integer) this.primaryKeyIndicies - .get(i)).intValue()); - - if (currentVal != null) { - this.updater.setBytes(numFields + i + 1, currentVal, false, - false); - } else { - this.updater.setNull(numFields + i + 1, 0); - } + int idx = ((Integer)this.primaryKeyIndicies.get(i)).intValue(); + this.setParamValue(this.updater, numFields + i + 1, this.thisRow, + idx , this.fields[idx].getSQLType()); } } }