@@ -14748,4 +14748,61 @@ public void testBug113336() throws Exception {
1474814748 } while (rwBS = !rwBS);
1474914749 }
1475014750
14751+ /**
14752+ * Tests fix for Bug#113130 (Bug#36043125), getGeneratedKeys() returns a zero resultset with non-key-generating statements.
14753+ *
14754+ * @throws SQLException
14755+ */
14756+ @Test
14757+ public void testBug113130() throws SQLException {
14758+ createTable("testBug113130NoAI", "(id INT PRIMARY KEY, data VARCHAR(100))");
14759+ createTable("testBug113130AI", "(id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(100))");
14760+
14761+ boolean allowMQ = false;
14762+ boolean rwBS = false;
14763+ do {
14764+ Properties props = new Properties();
14765+ props.setProperty(PropertyKey.allowMultiQueries.getKeyName(), Boolean.toString(allowMQ));
14766+ props.setProperty(PropertyKey.rewriteBatchedStatements.getKeyName(), Boolean.toString(rwBS));
14767+
14768+ for (int q = 1; q <= 5; q++) {
14769+ try (Connection testConn = getConnectionWithProps(props)) {
14770+ Statement testStmt = testConn.createStatement();
14771+ for (int i = 1; i <= q; i++) {
14772+ testStmt.addBatch(String.format("INSERT INTO testBug113130NoAI VALUES (%d, 'Data%d')", i, i));
14773+ }
14774+ int updCounts[] = testStmt.executeBatch();
14775+ assertEquals(q, updCounts.length);
14776+ for (int i = 0; i < q; i++) {
14777+ assertEquals(1, updCounts[i]);
14778+ }
14779+ this.rs = testStmt.getGeneratedKeys();
14780+ assertFalse(this.rs.next());
14781+ }
14782+
14783+ try (Connection testConn = getConnectionWithProps(props)) {
14784+ Statement testStmt = testConn.createStatement();
14785+ for (int i = 1; i <= q; i++) {
14786+ testStmt.addBatch(String.format("INSERT INTO testBug113130AI (data) VALUES ('Data%d')", i));
14787+ }
14788+ int updCounts[] = testStmt.executeBatch();
14789+ assertEquals(q, updCounts.length);
14790+ for (int i = 0; i < q; i++) {
14791+ assertEquals(1, updCounts[i]);
14792+ }
14793+ this.rs = testStmt.getGeneratedKeys();
14794+ for (int i = 1; i <= q; i++) {
14795+ assertTrue(this.rs.next());
14796+ assertEquals(i, this.rs.getInt(1));
14797+ }
14798+ assertFalse(this.rs.next());
14799+ }
14800+
14801+ this.stmt.execute("TRUNCATE TABLE testBug113130NoAI");
14802+ this.stmt.execute("TRUNCATE TABLE testBug113130AI");
14803+ this.stmt.execute("ALTER TABLE testBug113130AI AUTO_INCREMENT = 1");
14804+ }
14805+ } while ((allowMQ = !allowMQ) || (rwBS = !rwBS));
14806+ }
14807+
1475114808}
0 commit comments