Skip to content

Commit 9f14917

Browse files
committed
Fix for Bug#106435 (33850099), 8.0.28 Connector/J has regressive in setAutoCommit after Bug#104067 (33054827).
1 parent b8c0973 commit 9f14917

File tree

3 files changed

+88
-40
lines changed

3 files changed

+88
-40
lines changed

CHANGES

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

44
Version 8.0.29
55

6+
- Fix for Bug#106435 (33850099), 8.0.28 Connector/J has regressive in setAutoCommit after Bug#104067 (33054827).
7+
68
- Fix for Bug#106240 (33781440), StringIndexOutOfBoundsException when VALUE is at the end of the query.
79

810
- Fix for Bug#106397 (33893591), Contribution: fix: fix LocalizedErrorMessages.properties doc: less then -> ...

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,10 +2015,10 @@ void forEach(ConnectionLifecycleInterceptor each) throws SQLException {
20152015
this.autoReconnect.setValue(true);
20162016
}
20172017

2018-
boolean isAutocommit = this.session.getServerSession().isAutocommit();
2018+
boolean isAutoCommit = this.session.getServerSession().isAutoCommit();
20192019
try {
20202020
boolean needsSetOnServer = true;
2021-
if (this.useLocalSessionState.getValue() && isAutocommit == autoCommitFlag) {
2021+
if (this.useLocalSessionState.getValue() && isAutoCommit == autoCommitFlag) {
20222022
needsSetOnServer = false;
20232023
} else if (!this.autoReconnect.getValue()) {
20242024
needsSetOnServer = getSession().isSetNeededForAutoCommitMode(autoCommitFlag);
@@ -2037,7 +2037,7 @@ void forEach(ConnectionLifecycleInterceptor each) throws SQLException {
20372037
throw e;
20382038
} catch (CJException e) {
20392039
// Reset to current autocommit value in case of an exception different than a communication exception occurs.
2040-
this.session.getServerSession().setAutoCommit(isAutocommit);
2040+
this.session.getServerSession().setAutoCommit(isAutoCommit);
20412041
// Update the stacktrace.
20422042
throw SQLError.createSQLException(e.getMessage(), e.getSQLState(), e.getVendorCode(), e.isTransient(), e, getExceptionInterceptor());
20432043
} finally {

src/test/java/testsuite/regression/ConnectionRegressionTest.java

Lines changed: 83 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11562,63 +11562,109 @@ public void testBug28725534() throws Exception {
1156211562

1156311563
/**
1156411564
* Tests fix for Bug#104067 (33054827), No reset autoCommit after unknown issue occurs.
11565+
* Tests fix for Bug#106435 (33850099), 8.0.28 Connector/J has regressive in setAutoCommit after Bug#104067 (33054827).
1156511566
*
1156611567
* @throws Exception
1156711568
*/
1156811569
@Test
11569-
public void testBug104067() throws Exception {
11570+
public void testBug104067AndBug106435() throws Exception {
1157011571
Properties props = new Properties();
1157111572
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
1157211573
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
1157311574
props.setProperty(PropertyKey.queryInterceptors.getKeyName(), Bug104067QueryInterceptor.class.getName());
11574-
Connection testConn = getConnectionWithProps(props);
11575-
Statement testStmt = testConn.createStatement();
1157611575

11577-
// Connection vs session autocommit value:
11578-
// 1. Default value.
11579-
assertTrue(testConn.getAutoCommit());
11580-
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11581-
assertTrue(this.rs.next());
11582-
assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
11576+
// Connection vs session autocommit value - error on setAutoCommit(false).
11577+
try (Connection testConn = getConnectionWithProps(props); Statement testStmt = testConn.createStatement()) {
11578+
// 1. Initial value - true.
11579+
assertTrue(testConn.getAutoCommit());
11580+
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11581+
assertTrue(this.rs.next());
11582+
assertEquals("ON", this.rs.getString(2).toUpperCase());
1158311583

11584-
// 2. After Connection.setAutcommit(true).
11585-
try {
11586-
testConn.setAutoCommit(true);
11587-
} catch (SQLException e) {
11588-
fail("Exception not expected.", e);
11584+
// 2. After Connection.setAutcommit(true).
11585+
try {
11586+
testConn.setAutoCommit(true);
11587+
} catch (SQLException e) {
11588+
fail("Exception not expected.", e);
11589+
}
11590+
assertTrue(testConn.getAutoCommit());
11591+
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11592+
assertTrue(this.rs.next());
11593+
assertEquals("ON", this.rs.getString(2).toUpperCase());
11594+
11595+
// 3. After Connection.setAutcommit(false) & ERROR.
11596+
assertThrows(SQLException.class, () -> {
11597+
testConn.setAutoCommit(false);
11598+
return null;
11599+
});
11600+
assertTrue(testConn.getAutoCommit());
11601+
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11602+
this.rs.next();
11603+
assertEquals("ON", this.rs.getString(2).toUpperCase());
11604+
11605+
// 4. After Connection.setAutcommit(true).
11606+
try {
11607+
testConn.setAutoCommit(true);
11608+
} catch (SQLException e) {
11609+
fail("Exception not expected.", e);
11610+
}
11611+
assertTrue(testConn.getAutoCommit());
11612+
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11613+
assertTrue(this.rs.next());
11614+
assertEquals("ON", this.rs.getString(2).toUpperCase());
1158911615
}
11590-
assertTrue(testConn.getAutoCommit());
11591-
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11592-
assertTrue(this.rs.next());
11593-
assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
1159411616

11595-
// 3. After Connection.setAutcommit(false).
11596-
assertThrows(SQLException.class, () -> {
11597-
testConn.setAutoCommit(false);
11598-
return null;
11599-
});
11600-
assertTrue(testConn.getAutoCommit());
11601-
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11602-
this.rs.next();
11603-
assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
11617+
// Connection vs session autocommit value - error on setAutoCommit(true).
11618+
try (Connection testConn = getConnectionWithProps(props); Statement testStmt = testConn.createStatement()) {
11619+
Bug104067QueryInterceptor.errorOnSetTrue = true;
1160411620

11605-
// 4. After Connection.setAutcommit(true).
11606-
try {
11607-
testConn.setAutoCommit(true);
11608-
} catch (SQLException e) {
11609-
fail("Exception not expected.", e);
11621+
// 1. Initial value - true.
11622+
assertTrue(testConn.getAutoCommit());
11623+
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11624+
assertTrue(this.rs.next());
11625+
assertEquals("ON", this.rs.getString(2).toUpperCase());
11626+
11627+
// 2. After Connection.setAutcommit(false)
11628+
try {
11629+
testConn.setAutoCommit(false);
11630+
} catch (SQLException e) {
11631+
fail("Exception not expected.", e);
11632+
}
11633+
assertFalse(testConn.getAutoCommit());
11634+
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11635+
assertTrue(this.rs.next());
11636+
assertEquals("OFF", this.rs.getString(2).toUpperCase());
11637+
11638+
// 3. After Connection.setAutcommit(true) & ERROR.
11639+
assertThrows(SQLException.class, () -> {
11640+
testConn.setAutoCommit(true);
11641+
return null;
11642+
});
11643+
assertFalse(testConn.getAutoCommit());
11644+
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11645+
assertTrue(this.rs.next());
11646+
assertEquals("OFF", this.rs.getString(2).toUpperCase());
11647+
11648+
// 4. After Connection.setAutcommit(false).
11649+
try {
11650+
testConn.setAutoCommit(false);
11651+
} catch (SQLException e) {
11652+
fail("Exception not expected.", e);
11653+
}
11654+
assertFalse(testConn.getAutoCommit());
11655+
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11656+
this.rs.next();
11657+
assertEquals("OFF", this.rs.getString(2).toUpperCase());
1161011658
}
11611-
assertTrue(testConn.getAutoCommit());
11612-
this.rs = testStmt.executeQuery("SHOW SESSION VARIABLES LIKE 'autocommit'");
11613-
assertTrue(this.rs.next());
11614-
assertTrue(this.rs.getString(2).equalsIgnoreCase("ON"));
1161511659
}
1161611660

1161711661
public static class Bug104067QueryInterceptor extends BaseQueryInterceptor {
11662+
public static boolean errorOnSetTrue = false;
11663+
1161811664
@Override
1161911665
public <T extends Resultset> T preProcess(Supplier<String> str, Query interceptedQuery) {
1162011666
String sql = str.get();
11621-
if (sql.equalsIgnoreCase("SET autocommit=0")) {
11667+
if (errorOnSetTrue && sql.equalsIgnoreCase("SET autocommit=1") || !errorOnSetTrue && sql.equalsIgnoreCase("SET autocommit=0")) {
1162211668
throw ExceptionFactory.createException("Artificial non-connection related exception while executing \"" + sql + "\"");
1162311669
}
1162411670
return super.preProcess(str, interceptedQuery);

0 commit comments

Comments
 (0)