Skip to content

Commit 3b9c627

Browse files
committed
Fix for Bug#113336 (Bug#36080226), Inconsistent getUpdateCount() Behavior with allowMultiQueries.
Change-Id: I95db599dbbb1867c626cc42e0045710e2e16b3a5
1 parent b369d81 commit 3b9c627

4 files changed

Lines changed: 93 additions & 79 deletions

File tree

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 9.6.0
55

6+
- Fix for Bug#113336 (Bug#36080226), Inconsistent getUpdateCount() Behavior with allowMultiQueries.
7+
68
- Fix for Bug#118234 (Bug#37975837), A potential bugs in Mysql Connector/J.
79

810
- Fix for Bug#113413 (Bug#36107426), Connection.changeUser cannot be done after DriverManager.loginTimeout elapses.

src/build/java/instrumentation/TranslateExceptions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ public static void main(String[] args) throws Exception {
390390
catchRuntimeException(clazz, clazz.getDeclaredMethod("getBatchedGeneratedKeys", new CtClass[] { ctStatement }), EXCEPTION_INTERCEPTOR_GETTER);
391391
catchRuntimeException(clazz, clazz.getDeclaredMethod("getGeneratedKeysInternal", new CtClass[] { CtClass.longType }), EXCEPTION_INTERCEPTOR_GETTER);
392392
catchRuntimeException(clazz, clazz.getDeclaredMethod("getLastInsertID", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
393-
catchRuntimeException(clazz, clazz.getDeclaredMethod("getLongUpdateCount", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
394393
catchRuntimeException(clazz, clazz.getDeclaredMethod("getOpenResultSetCount", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
395394
catchRuntimeException(clazz, clazz.getDeclaredMethod("getResultSetInternal", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
396395
catchRuntimeException(clazz, clazz.getDeclaredMethod("processMultiCountsAndKeys", new CtClass[] { ctStatementImpl, CtClass.intType, ctLongArray }),

src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ protected void implicitlyCloseAllOpenResults() throws SQLException {
478478
this.generatedKeysResults.doClose(CloseOption.IMPLICIT);
479479
}
480480
closeAllOpenResults();
481+
this.results = null;
482+
this.generatedKeysResults = null;
481483
}
482484
}
483485

@@ -1060,7 +1062,6 @@ private long[] executeBatchUsingMultiQueries(long individualStatementTimeout) th
10601062
int escapeAdjust = 1;
10611063

10621064
batchStmt.setEscapeProcessing(this.doEscapeProcessing);
1063-
10641065
if (this.doEscapeProcessing) {
10651066
escapeAdjust = 2; // We assume packet _could_ grow by this amount, as we're not sure how big statement will end up after escape processing
10661067
}
@@ -1143,6 +1144,7 @@ protected int processMultiCountsAndKeys(StatementImpl batchedStatement, int upda
11431144
connectionLock.lock();
11441145
try {
11451146
updateCounts[updateCountCounter++] = batchedStatement.getLargeUpdateCount();
1147+
this.updateCount = batchedStatement.getLargeUpdateCount();
11461148

11471149
boolean doGenKeys = this.batchedGeneratedKeys != null;
11481150

@@ -1158,6 +1160,7 @@ protected int processMultiCountsAndKeys(StatementImpl batchedStatement, int upda
11581160

11591161
while (batchedStatement.getMoreResults() || batchedStatement.getLargeUpdateCount() != -1) {
11601162
updateCounts[updateCountCounter++] = batchedStatement.getLargeUpdateCount();
1163+
this.updateCount = batchedStatement.getLargeUpdateCount();
11611164

11621165
if (doGenKeys) {
11631166
long generatedKey = batchedStatement.getLastInsertID();
@@ -1648,31 +1651,6 @@ public long getLastInsertID() {
16481651
}
16491652
}
16501653

1651-
/**
1652-
* getLongUpdateCount returns the current result as an update count, if the
1653-
* result is a ResultSet or there are no more results, -1 is returned. It
1654-
* should only be called once per result.
1655-
*
1656-
* <p>
1657-
* This method returns longs as MySQL server returns 64-bit values for update counts
1658-
* </p>
1659-
*
1660-
* @return the current update count.
1661-
*/
1662-
public long getLongUpdateCount() {
1663-
Lock connectionLock = checkClosed().getConnectionLock();
1664-
connectionLock.lock();
1665-
try {
1666-
if (this.results == null || this.results.hasRows()) {
1667-
return -1;
1668-
}
1669-
1670-
return this.updateCount;
1671-
} finally {
1672-
connectionLock.unlock();
1673-
}
1674-
}
1675-
16761654
@Override
16771655
public int getMaxFieldSize() throws SQLException {
16781656
Lock connectionLock = checkClosed().getConnectionLock();
@@ -2349,11 +2327,11 @@ public long getLargeUpdateCount() throws SQLException {
23492327
Lock connectionLock = checkClosed().getConnectionLock();
23502328
connectionLock.lock();
23512329
try {
2352-
if (this.results == null || this.results.hasRows()) {
2353-
return -1;
2330+
if (this.results != null) {
2331+
return this.results.hasRows() ? -1 : this.results.getUpdateCount();
23542332
}
23552333

2356-
return this.results.getUpdateCount();
2334+
return this.updateCount;
23572335
} finally {
23582336
connectionLock.unlock();
23592337
}

0 commit comments

Comments
 (0)