Skip to content

Commit dd61577

Browse files
committed
Fix for Bug#21978230, COMMENT PARSING NOT PROPER IN PREPSTMT.EXECUTEBATCH().
1 parent 582d91f commit dd61577

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
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#21978230, COMMENT PARSING NOT PROPER IN PREPSTMT.EXECUTEBATCH().
7+
68
- Fix for Bug#81468 (23312764), MySQL server fails to rewrite batch insert when column name contains word select.
79

810
- Fix for Bug#106435 (33850099), 8.0.28 Connector/J has regressive in setAutoCommit after Bug#104067 (33054827).

src/test/java/testsuite/regression/StatementRegressionTest.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import java.util.concurrent.Future;
103103
import java.util.concurrent.TimeUnit;
104104
import java.util.concurrent.TimeoutException;
105+
import java.util.function.Consumer;
105106
import java.util.function.Supplier;
106107
import java.util.function.ToIntFunction;
107108

@@ -12285,4 +12286,98 @@ private int countValues(String query) {
1228512286
}
1228612287
}
1228712288

12289+
/**
12290+
* Tests for Bug#21978230, COMMENT PARSING NOT PROPER IN PREPSTMT.EXECUTEBATCH().
12291+
*
12292+
* @throws Exception
12293+
*/
12294+
@Test
12295+
public void testBug21978230() throws Exception {
12296+
createTable("testBug21978230", "(c1 INT, c2 INT, t VARCHAR(100))");
12297+
12298+
Properties props = new Properties();
12299+
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
12300+
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
12301+
props.setProperty(PropertyKey.rewriteBatchedStatements.getKeyName(), "true");
12302+
props.setProperty(PropertyKey.continueBatchOnError.getKeyName(), "false");
12303+
props.setProperty(PropertyKey.emulateUnsupportedPstmts.getKeyName(), "true");
12304+
Connection testConn = getConnectionWithProps(props);
12305+
12306+
Consumer<String> runQueryAndAssertResults = (query) -> {
12307+
try {
12308+
this.pstmt = testConn.prepareStatement(query);
12309+
this.pstmt.setInt(1, 1);
12310+
this.pstmt.setInt(2, 10);
12311+
this.pstmt.setString(3, "A");
12312+
this.pstmt.setString(4, "A");
12313+
this.pstmt.addBatch();
12314+
this.pstmt.setInt(1, 2);
12315+
this.pstmt.setInt(2, 20);
12316+
this.pstmt.setString(3, "B");
12317+
this.pstmt.setString(4, "B");
12318+
this.pstmt.addBatch();
12319+
this.pstmt.setInt(1, 3);
12320+
this.pstmt.setInt(2, 30);
12321+
this.pstmt.setString(3, "C");
12322+
this.pstmt.setString(4, "C");
12323+
this.pstmt.addBatch();
12324+
this.pstmt.setInt(1, 4);
12325+
this.pstmt.setInt(2, 40);
12326+
this.pstmt.setString(3, "D");
12327+
this.pstmt.setString(4, "D");
12328+
this.pstmt.addBatch();
12329+
this.pstmt.executeBatch();
12330+
12331+
this.rs = this.stmt.executeQuery("SELECT * FROM testBug21978230");
12332+
for (int i = 1; i <= 4; i++) {
12333+
assertTrue(this.rs.next());
12334+
assertEquals(i, this.rs.getInt(1));
12335+
assertEquals(i * 10, this.rs.getInt(2));
12336+
char chr = (char) ('A' + i - 1);
12337+
assertEquals(chr + "^^^^" + chr, this.rs.getString(3));
12338+
}
12339+
assertFalse(this.rs.next());
12340+
} catch (SQLException e) {
12341+
throw new RuntimeException(e);
12342+
}
12343+
};
12344+
12345+
/*
12346+
* Expected: "Parameter index out of range".
12347+
*/
12348+
this.stmt.execute("TRUNCATE TABLE testBug21978230");
12349+
Exception ex = assertThrows(RuntimeException.class, ".*Parameter index out of range \\(3 > number of parameters, which is 2\\)\\.", () -> {
12350+
runQueryAndAssertResults.accept("REPLACE INTO testBug21978230 VALUES (?, ?, /*/ CONCAT(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDATE v=concat(v,?)*/");
12351+
return null;
12352+
});
12353+
assertEquals(ex.getCause().getClass(), SQLException.class);
12354+
12355+
this.stmt.execute("TRUNCATE TABLE testBug21978230");
12356+
ex = assertThrows(RuntimeException.class, ".*Parameter index out of range \\(3 > number of parameters, which is 2\\)\\.", () -> {
12357+
runQueryAndAssertResults.accept("INSERT INTO testBug21978230 VALUES (?, ?, /*/ CONCAT(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDATE v=concat(v,?)*/");
12358+
return null;
12359+
});
12360+
assertEquals(ex.getCause().getClass(), SQLException.class);
12361+
12362+
/*
12363+
* Expected: 4 records inserted in each query
12364+
*/
12365+
this.stmt.execute("TRUNCATE TABLE testBug21978230");
12366+
runQueryAndAssertResults.accept("REPLACE INTO testBug21978230 VALUES (?, ?, /**/ CONCAT(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDATE v=concat(v,?)*/");
12367+
12368+
this.stmt.execute("TRUNCATE TABLE testBug21978230");
12369+
runQueryAndAssertResults.accept("INSERT INTO testBug21978230 VALUES (?, ?, /**/ CONCAT(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDATE v=concat(v,?)*/");
12370+
12371+
this.stmt.execute("TRUNCATE TABLE testBug21978230");
12372+
runQueryAndAssertResults.accept("REPLACE INTO testBug21978230 VALUES (?, ?, concat(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDaTE v=concat(v,?)*/");
12373+
12374+
this.stmt.execute("TRUNCATE TABLE testBug21978230");
12375+
runQueryAndAssertResults.accept("INSERT INTO testBug21978230 VALUES (?, ?, concat(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDaTE v=concat(v,?)*/");
12376+
12377+
this.stmt.execute("TRUNCATE TABLE testBug21978230");
12378+
runQueryAndAssertResults.accept("REPLACE INTO testBug21978230 VALUES(?, ?, /* comment */CONCAT(?, '^^^^', ?))");
12379+
12380+
this.stmt.execute("TRUNCATE TABLE testBug21978230");
12381+
runQueryAndAssertResults.accept("INSERT INTO testBug21978230 VALUES(?, ?, /* comment */CONCAT(?, '^^^^', ?))");
12382+
}
1228812383
}

0 commit comments

Comments
 (0)