Modified:
trunk/
trunk/src/com/mysql/jdbc/ConnectionProperties.java
trunk/src/com/mysql/jdbc/ConnectionPropertiesImpl.java
trunk/src/com/mysql/jdbc/LocalizedErrorMessages.properties
trunk/src/com/mysql/jdbc/PreparedStatement.java
trunk/src/com/mysql/jdbc/ReplicationConnection.java
trunk/src/com/mysql/jdbc/ServerPreparedStatement.java
trunk/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java
Log:
Merged revisions 6801-6802 via svnmerge from
svn+ssh://mmatthews@stripped/connectors-svnroot/connector-j/branches/branch_5_1
.......
r6801 | mmatthews | 2008-07-30 10:05:57 -0500 (Wed, 30 Jul 2008) | 1 line
First cut at a way to compensate for update counts of 2 and 0 for INSERT ... ON DUPLICATE KEY UPDATE statements.
.......
r6802 | mmatthews | 2008-07-30 10:08:38 -0500 (Wed, 30 Jul 2008) | 1 line
Updated svn-ingores.
.......
Property changes on: trunk
___________________________________________________________________
Name: svnmerge-integrated
- /branches/branch_5_0:1-6636,6638-6670 /branches/branch_5_1:1-6582,6584-6678,6680-6799
+ /branches/branch_5_0:1-6636,6638-6670 /branches/branch_5_1:1-6582,6584-6678,6680-6803
Modified: trunk/src/com/mysql/jdbc/ConnectionProperties.java
===================================================================
--- trunk/src/com/mysql/jdbc/ConnectionProperties.java 2008-07-30 15:11:08 UTC (rev 6803)
+++ trunk/src/com/mysql/jdbc/ConnectionProperties.java 2008-07-30 15:21:15 UTC (rev 6804)
@@ -1603,7 +1603,11 @@
public abstract void setUseLocalTransactionState(boolean flag);
- public String getMysqlIOFactory();
+ public String getMysqlIOFactory();
- public void setMysqlIOFactory(String mysqlIOFactoryClassName);
+ public void setMysqlIOFactory(String mysqlIOFactoryClassName);
+
+ public abstract boolean getCompensateOnDuplicateKeyUpdateCounts();
+
+ public abstract void setCompensateOnDuplicateKeyUpdateCounts(boolean flag);
}
Modified: trunk/src/com/mysql/jdbc/ConnectionPropertiesImpl.java
===================================================================
--- trunk/src/com/mysql/jdbc/ConnectionPropertiesImpl.java 2008-07-30 15:11:08 UTC (rev 6803)
+++ trunk/src/com/mysql/jdbc/ConnectionPropertiesImpl.java 2008-07-30 15:21:15 UTC (rev 6804)
@@ -849,6 +849,11 @@
Messages.getString("ConnectionProperties.clobCharacterEncoding"), //$NON-NLS-1$
"5.0.0", MISC_CATEGORY, Integer.MIN_VALUE); //$NON-NLS-1$
+ private BooleanConnectionProperty compensateOnDuplicateKeyUpdateCounts = new BooleanConnectionProperty(
+ "compensateOnDuplicateKeyUpdateCounts",
+ false,
+ Messages.getString("ConnectionProperties.compensateOnDuplicateKeyUpdateCounts"),
+ "5.1.7", MISC_CATEGORY, Integer.MIN_VALUE);
private StringConnectionProperty connectionCollation = new StringConnectionProperty(
"connectionCollation", //$NON-NLS-1$
null,
@@ -4407,4 +4412,12 @@
public void setUseLocalTransactionState(boolean flag) {
this.useLocalTransactionState.setValue(flag);
}
+
+ public boolean getCompensateOnDuplicateKeyUpdateCounts() {
+ return this.compensateOnDuplicateKeyUpdateCounts.getValueAsBoolean();
+ }
+
+ public void setCompensateOnDuplicateKeyUpdateCounts(boolean flag) {
+ this.compensateOnDuplicateKeyUpdateCounts.setValue(flag);
+ }
}
Modified: trunk/src/com/mysql/jdbc/LocalizedErrorMessages.properties
===================================================================
--- trunk/src/com/mysql/jdbc/LocalizedErrorMessages.properties 2008-07-30 15:11:08 UTC (rev 6803)
+++ trunk/src/com/mysql/jdbc/LocalizedErrorMessages.properties 2008-07-30 15:21:15 UTC (rev 6804)
@@ -476,6 +476,7 @@
ConnectionProperties.clientInfoProvider=The name of a class that implements the com.mysql.jdbc.JDBC4ClientInfoProvider interface in order to support JDBC-4.0's Connection.get/setClientInfo() methods
ConnectionProperties.clobberStreamingResults=This will cause a 'streaming' ResultSet to be automatically closed, and any outstanding data still streaming from the server to be discarded if another query is executed before all the data has been read from the server.
ConnectionProperties.clobCharacterEncoding=The character encoding to use for sending and retrieving TEXT, MEDIUMTEXT and LONGTEXT values instead of the configured connection characterEncoding
+ConnectionProperties.compensateOnDuplicateKeyUpdateCounts=Should the driver compensate for the update counts of "ON DUPLICATE KEY" INSERT statements (2 = 1, 0 = 1) when using prepared statements?
ConnectionProperties.connectionCollation=If set, tells the server to use this collation via 'set collation_connection'
ConnectionProperties.connectionLifecycleInterceptors=A comma-delimited list of classes that implement "com.mysql.jdbc.ConnectionLifecycleInterceptor" that should notified of connection lifecycle events (creation, destruction, commit, rollback, setCatalog and setAutoCommit) and potentially alter the execution of these commands. ConnectionLifecycleInterceptors are "stackable", more than one interceptor may be specified via the configuration property as a comma-delimited list, with the interceptors executed in order from left to right.
ConnectionProperties.connectTimeout=Timeout for socket connect (in milliseconds), with 0 being no timeout. Only works on JDK-1.4 or newer. Defaults to '0'.
Modified: trunk/src/com/mysql/jdbc/PreparedStatement.java
===================================================================
--- trunk/src/com/mysql/jdbc/PreparedStatement.java 2008-07-30 15:11:08 UTC (rev 6803)
+++ trunk/src/com/mysql/jdbc/PreparedStatement.java 2008-07-30 15:21:15 UTC (rev 6804)
@@ -181,6 +181,8 @@
byte[][] staticSql = null;
+ boolean isOnDuplicateKeyUpdate = false;
+
/**
* Represents the "parsed" state of a client-side
* prepared statement, with the statement broken up into
@@ -197,6 +199,8 @@
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
+ this.isOnDuplicateKeyUpdate = containsOnDuplicateKeyInString(sql);
+
this.lastUsed = System.currentTimeMillis();
String quotedIdentifierString = dbmd.getIdentifierQuoteString();
@@ -522,6 +526,8 @@
private SimpleDateFormat ddf;
private SimpleDateFormat tdf;
+ private boolean compensateForOnDuplicateKeyUpdate = false;
+
/**
* Creates a prepared statement instance -- We need to provide factory-style
* methods so we can support both JDBC3 (and older) and JDBC4 runtimes,
@@ -588,6 +594,8 @@
public PreparedStatement(ConnectionImpl conn, String catalog)
throws SQLException {
super(conn, catalog);
+
+ this.compensateForOnDuplicateKeyUpdate = this.connection.getCompensateOnDuplicateKeyUpdateCounts();
}
/**
@@ -628,6 +636,8 @@
this.charEncoding, this.charConverter);
initializeFromParseInfo();
+
+ this.compensateForOnDuplicateKeyUpdate = this.connection.getCompensateOnDuplicateKeyUpdateCounts();
}
/**
@@ -665,6 +675,8 @@
this.usingAnsiMode = !this.connection.useAnsiQuotedIdentifiers();
initializeFromParseInfo();
+
+ this.compensateForOnDuplicateKeyUpdate = this.connection.getCompensateOnDuplicateKeyUpdateCounts();
}
/**
@@ -1105,7 +1117,7 @@
this.canRewrite = StringUtils.startsWithIgnoreCaseAndWs(
this.originalSql, "INSERT", this.statementAfterCommentsPos)
&& StringUtils.indexOfIgnoreCaseRespectMarker(this.statementAfterCommentsPos, this.originalSql, "SELECT", "\"'`", "\"'`", false) == -1
- && StringUtils.indexOfIgnoreCaseRespectMarker(this.statementAfterCommentsPos, this.originalSql, "UPDATE", "\"'`", "\"'`", false) == -1;
+ && !containsOnDuplicateKeyUpdateInSQL();
this.hasCheckedForRewrite = true;
}
@@ -2037,6 +2049,13 @@
this.results = rs;
this.updateCount = rs.getUpdateCount();
+
+ if (containsOnDuplicateKeyUpdateInSQL() &&
+ this.compensateForOnDuplicateKeyUpdate) {
+ if (this.updateCount == 2 || this.updateCount == 0) {
+ this.updateCount = 1;
+ }
+ }
int truncatedUpdateCount = 0;
@@ -2051,6 +2070,10 @@
return truncatedUpdateCount;
}
+ protected boolean containsOnDuplicateKeyUpdateInSQL() {
+ return this.parseInfo.isOnDuplicateKeyUpdate;
+ }
+
private String extractValuesClause() throws SQLException {
if (this.batchedValuesClause == null) {
String quoteCharStr = this.connection.getMetaData()
@@ -5142,4 +5165,23 @@
public String getPreparedSql() {
return this.originalSql;
}
+
+ @Override
+ public int getUpdateCount() throws SQLException {
+ int count = super.getUpdateCount();
+
+ if (containsOnDuplicateKeyUpdateInSQL() &&
+ this.compensateForOnDuplicateKeyUpdate) {
+ if (count == 2 || count == 0) {
+ count = 1;
+ }
+ }
+
+ return count;
+ }
+
+ protected boolean containsOnDuplicateKeyInString(String sql) {
+ return StringUtils.indexOfIgnoreCaseRespectMarker(0,
+ sql, " ON DUPLICATE KEY UPDATE ", "\"'`", "\"'`", !this.connection.isNoBackslashEscapesSet()) != -1;
+ }
}
Modified: trunk/src/com/mysql/jdbc/ReplicationConnection.java
===================================================================
--- trunk/src/com/mysql/jdbc/ReplicationConnection.java 2008-07-30 15:11:08 UTC (rev 6803)
+++ trunk/src/com/mysql/jdbc/ReplicationConnection.java 2008-07-30 15:21:15 UTC (rev 6804)
@@ -2354,4 +2354,13 @@
// TODO Auto-generated method stub
}
+
+ public boolean getCompensateOnDuplicateKeyUpdateCounts() {
+ return this.currentConnection.getCompensateOnDuplicateKeyUpdateCounts();
+ }
+
+ public void setCompensateOnDuplicateKeyUpdateCounts(boolean flag) {
+ // TODO Auto-generated method stub
+
+ }
}
Modified: trunk/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
--- trunk/src/com/mysql/jdbc/ServerPreparedStatement.java 2008-07-30 15:11:08 UTC (rev 6803)
+++ trunk/src/com/mysql/jdbc/ServerPreparedStatement.java 2008-07-30 15:21:15 UTC (rev 6804)
@@ -265,6 +265,8 @@
* (seconds) + 4 (microseconds)
*/
private static final byte MAX_TIME_REP_LENGTH = 13;
+
+ private boolean hasOnDuplicateKeyUpdate = false;
private void storeTime(Buffer intoBuf, Time tm) throws SQLException {
@@ -390,6 +392,8 @@
checkNullOrEmptyQuery(sql);
+ this.hasOnDuplicateKeyUpdate = containsOnDuplicateKeyInString(sql);
+
int startOfStatement = findStartOfStatement(sql);
this.firstCharOfStmt = StringUtils.firstAlphaCharUc(sql, startOfStatement);
@@ -2894,5 +2898,7 @@
return batchedParamIndex;
}
-
+ protected boolean containsOnDuplicateKeyUpdateInSQL() {
+ return this.hasOnDuplicateKeyUpdate;
+ }
}
Modified: trunk/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java
===================================================================
--- trunk/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2008-07-30 15:11:08 UTC (rev 6803)
+++ trunk/src/com/mysql/jdbc/jdbc2/optional/ConnectionWrapper.java 2008-07-30 15:21:15 UTC (rev 6804)
@@ -2563,4 +2563,12 @@
public void setUseLocalTransactionState(boolean flag) {
this.mc.setUseLocalTransactionState(flag);
}
+
+ public boolean getCompensateOnDuplicateKeyUpdateCounts() {
+ return this.mc.getCompensateOnDuplicateKeyUpdateCounts();
+ }
+
+ public void setCompensateOnDuplicateKeyUpdateCounts(boolean flag) {
+ this.mc.setCompensateOnDuplicateKeyUpdateCounts(flag);
+ }
}
| Thread |
|---|
| • Connector/J commit: r6804 - in trunk: . src/com/mysql/jdbc src/com/mysql/jdbc/jdbc2/optional | mmatthews | 30 Jul |