Skip to content

Commit

Permalink
Fix for Bug#21978230, COMMENT PARSING NOT PROPER IN PREPSTMT.EXECUTEB…
Browse files Browse the repository at this point in the history
…ATCH().
  • Loading branch information
fjssilva committed Mar 8, 2022
1 parent 582d91f commit dd61577
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 8.0.29

- Fix for Bug#21978230, COMMENT PARSING NOT PROPER IN PREPSTMT.EXECUTEBATCH().

- Fix for Bug#81468 (23312764), MySQL server fails to rewrite batch insert when column name contains word select.

- Fix for Bug#106435 (33850099), 8.0.28 Connector/J has regressive in setAutoCommit after Bug#104067 (33054827).
Expand Down
95 changes: 95 additions & 0 deletions src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.function.ToIntFunction;

Expand Down Expand Up @@ -12285,4 +12286,98 @@ private int countValues(String query) {
}
}

/**
* Tests for Bug#21978230, COMMENT PARSING NOT PROPER IN PREPSTMT.EXECUTEBATCH().
*
* @throws Exception
*/
@Test
public void testBug21978230() throws Exception {
createTable("testBug21978230", "(c1 INT, c2 INT, t VARCHAR(100))");

Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.rewriteBatchedStatements.getKeyName(), "true");
props.setProperty(PropertyKey.continueBatchOnError.getKeyName(), "false");
props.setProperty(PropertyKey.emulateUnsupportedPstmts.getKeyName(), "true");
Connection testConn = getConnectionWithProps(props);

Consumer<String> runQueryAndAssertResults = (query) -> {
try {
this.pstmt = testConn.prepareStatement(query);
this.pstmt.setInt(1, 1);
this.pstmt.setInt(2, 10);
this.pstmt.setString(3, "A");
this.pstmt.setString(4, "A");
this.pstmt.addBatch();
this.pstmt.setInt(1, 2);
this.pstmt.setInt(2, 20);
this.pstmt.setString(3, "B");
this.pstmt.setString(4, "B");
this.pstmt.addBatch();
this.pstmt.setInt(1, 3);
this.pstmt.setInt(2, 30);
this.pstmt.setString(3, "C");
this.pstmt.setString(4, "C");
this.pstmt.addBatch();
this.pstmt.setInt(1, 4);
this.pstmt.setInt(2, 40);
this.pstmt.setString(3, "D");
this.pstmt.setString(4, "D");
this.pstmt.addBatch();
this.pstmt.executeBatch();

this.rs = this.stmt.executeQuery("SELECT * FROM testBug21978230");
for (int i = 1; i <= 4; i++) {
assertTrue(this.rs.next());
assertEquals(i, this.rs.getInt(1));
assertEquals(i * 10, this.rs.getInt(2));
char chr = (char) ('A' + i - 1);
assertEquals(chr + "^^^^" + chr, this.rs.getString(3));
}
assertFalse(this.rs.next());
} catch (SQLException e) {
throw new RuntimeException(e);
}
};

/*
* Expected: "Parameter index out of range".
*/
this.stmt.execute("TRUNCATE TABLE testBug21978230");
Exception ex = assertThrows(RuntimeException.class, ".*Parameter index out of range \\(3 > number of parameters, which is 2\\)\\.", () -> {
runQueryAndAssertResults.accept("REPLACE INTO testBug21978230 VALUES (?, ?, /*/ CONCAT(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDATE v=concat(v,?)*/");
return null;
});
assertEquals(ex.getCause().getClass(), SQLException.class);

this.stmt.execute("TRUNCATE TABLE testBug21978230");
ex = assertThrows(RuntimeException.class, ".*Parameter index out of range \\(3 > number of parameters, which is 2\\)\\.", () -> {
runQueryAndAssertResults.accept("INSERT INTO testBug21978230 VALUES (?, ?, /*/ CONCAT(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDATE v=concat(v,?)*/");
return null;
});
assertEquals(ex.getCause().getClass(), SQLException.class);

/*
* Expected: 4 records inserted in each query
*/
this.stmt.execute("TRUNCATE TABLE testBug21978230");
runQueryAndAssertResults.accept("REPLACE INTO testBug21978230 VALUES (?, ?, /**/ CONCAT(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDATE v=concat(v,?)*/");

this.stmt.execute("TRUNCATE TABLE testBug21978230");
runQueryAndAssertResults.accept("INSERT INTO testBug21978230 VALUES (?, ?, /**/ CONCAT(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDATE v=concat(v,?)*/");

this.stmt.execute("TRUNCATE TABLE testBug21978230");
runQueryAndAssertResults.accept("REPLACE INTO testBug21978230 VALUES (?, ?, concat(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDaTE v=concat(v,?)*/");

this.stmt.execute("TRUNCATE TABLE testBug21978230");
runQueryAndAssertResults.accept("INSERT INTO testBug21978230 VALUES (?, ?, concat(?, '^^^^', ?)) /*ON DUPLICATE KEY UPDaTE v=concat(v,?)*/");

this.stmt.execute("TRUNCATE TABLE testBug21978230");
runQueryAndAssertResults.accept("REPLACE INTO testBug21978230 VALUES(?, ?, /* comment */CONCAT(?, '^^^^', ?))");

this.stmt.execute("TRUNCATE TABLE testBug21978230");
runQueryAndAssertResults.accept("INSERT INTO testBug21978230 VALUES(?, ?, /* comment */CONCAT(?, '^^^^', ?))");
}
}

0 comments on commit dd61577

Please sign in to comment.