=== modified file 'CHANGES' --- CHANGES 2009-09-22 14:00:29 +0000 +++ CHANGES 2009-10-19 20:04:15 +0000 @@ -1,6 +1,10 @@ # Changelog # $Id$ +mm-dd-yy - Version 5.1.11 (not yet released) + + - Fix for BUG#48172 - Batch rewrite requires space immediately after "VALUES" + 09-22-09 - Version 5.1.10 - Fix for BUG#47494 - Non standard port numbers in the URL are not honored. === modified file 'src/com/mysql/jdbc/PreparedStatement.java' --- src/com/mysql/jdbc/PreparedStatement.java 2009-08-26 14:47:30 +0000 +++ src/com/mysql/jdbc/PreparedStatement.java 2009-10-19 19:47:27 +0000 @@ -486,26 +486,25 @@ if (quoteCharStr.length() > 0) { indexOfValues = StringUtils.indexOfIgnoreCaseRespectQuotes( valuesSearchStart, - originalSql, "VALUES ", quoteCharStr.charAt(0), false); + originalSql, "VALUES", quoteCharStr.charAt(0), false); } else { indexOfValues = StringUtils.indexOfIgnoreCase(valuesSearchStart, originalSql, - "VALUES "); + "VALUES"); } - /* check if the char immediately preceding VALUES may be part of the table name */ + if (indexOfValues > 0) { + /* check if the char immediately preceding VALUES may be part of the table name */ char c = originalSql.charAt(indexOfValues - 1); - switch(c) { - case ' ': - case ')': - case '`': - case '\t': - case '\n': - break; - default: - valuesSearchStart = indexOfValues + 7; - indexOfValues = -1; - break; + if(!(Character.isWhitespace(c) || c == ')')){ + valuesSearchStart = indexOfValues + 6; + indexOfValues = -1; + } + /* check if the char immediately following VALUES may be whitespace or open parenthesis */ + c = originalSql.charAt(indexOfValues + 6); + if(!(Character.isWhitespace(c) || c == '(')){ + valuesSearchStart = indexOfValues + 6; + indexOfValues = -1; } } else { break; @@ -516,7 +515,7 @@ return null; } - int indexOfFirstParen = sql.indexOf('(', indexOfValues + 7); + int indexOfFirstParen = sql.indexOf('(', indexOfValues + 6); if (indexOfFirstParen == -1) { return null; === modified file 'src/testsuite/regression/StatementRegressionTest.java' --- src/testsuite/regression/StatementRegressionTest.java 2009-09-22 21:33:04 +0000 +++ src/testsuite/regression/StatementRegressionTest.java 2009-10-19 19:31:12 +0000 @@ -5835,6 +5835,64 @@ closeMemberJDBCResources(); } } + public void testBatchBug() throws Exception { + createTable( + "testBatchInsert", + "(a INT PRIMARY KEY AUTO_INCREMENT)"); + Connection rewriteConn = getConnectionWithProps("rewriteBatchedStatements=true,dumpQueriesOnException=true"); + assertEquals("0", getSingleIndexedValueWithQuery(rewriteConn, 2, + "SHOW SESSION STATUS LIKE 'Com_insert'").toString()); + + + this.pstmt = rewriteConn.prepareStatement("INSERT INTO testBatchInsert VALUES (?)"); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.executeBatch(); + + assertEquals("1", getSingleIndexedValueWithQuery(rewriteConn, 2, + "SHOW SESSION STATUS LIKE 'Com_insert'").toString()); + this.pstmt = rewriteConn.prepareStatement("INSERT INTO `testBatchInsert`VALUES (?)"); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.executeBatch(); + + assertEquals("2", getSingleIndexedValueWithQuery(rewriteConn, 2, + "SHOW SESSION STATUS LIKE 'Com_insert'").toString()); + + this.pstmt = rewriteConn.prepareStatement("INSERT INTO testBatchInsert VALUES(?)"); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.executeBatch(); + + assertEquals("3", getSingleIndexedValueWithQuery(rewriteConn, 2, + "SHOW SESSION STATUS LIKE 'Com_insert'").toString()); + + this.pstmt = rewriteConn.prepareStatement("INSERT INTO testBatchInsert VALUES\n(?)"); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.setNull(1, java.sql.Types.INTEGER); + this.pstmt.addBatch(); + this.pstmt.executeBatch(); + + assertEquals("4", getSingleIndexedValueWithQuery(rewriteConn, 2, + "SHOW SESSION STATUS LIKE 'Com_insert'").toString()); + + } + /** * Tests fix for Bug#41532 - regression in performance for batched inserts when using ON DUPLICATE KEY UPDATE