From: Date: June 28 2007 6:18pm Subject: Connector/J commit: r6471 - in branches: branch_5_0/connector-j branch_5_0/connector-j/src/com/mysql/jdbc branch_5_0/connector-j/src/testsuite/regression branch_5_1/connector-j branch_5_1/connector-j/src/com/mysql/jdbc branch_5_1/connector-j/src/testsuite/regression List-Archive: http://lists.mysql.com/commits/29875 X-Bug: 28851, 28596 Message-Id: <200706281618.l5SGIGlv002621@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/branch_5_0/connector-j/CHANGES branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java branches/branch_5_1/connector-j/CHANGES branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java Log: - Fixed BUG#28851 - parser in client-side prepared statements eats character following '/' if it's not a multi-line comment. - Fixed BUG#28596 - parser in client-side prepared statements runs to end of statement, rather than end-of-line for '#' comments. Also added support for '--' single-line comments. Modified: branches/branch_5_0/connector-j/CHANGES =================================================================== --- branches/branch_5_0/connector-j/CHANGES 2007-06-28 14:29:12 UTC (rev 6470) +++ branches/branch_5_0/connector-j/CHANGES 2007-06-28 16:18:10 UTC (rev 6471) @@ -73,7 +73,15 @@ with version 7), and uses the configuration bundle "coldFusion", which sets useDynamicCharsetInfo to "false" (see previous entry), and sets useLocalSessionState and autoReconnect to "true". - + + - Fixed BUG#28851 - parser in client-side prepared statements + eats character following '/' if it's not a multi-line comment. + + - Fixed BUG#28596 - parser in client-side prepared statements + runs to end of statement, rather than end-of-line for '#' comments. + + Also added support for '--' single-line comments. + 05-15-07 - Version 5.0.6 - Fixed BUG#25545 - Client options not sent correctly when using SSL, Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2007-06-28 14:29:12 UTC (rev 6470) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2007-06-28 16:18:10 UTC (rev 6471) @@ -225,22 +225,34 @@ quoteChar = 0; } } else { - if (c == '#') { - // run out to end of line - i = this.statementLength - 1; + if (c == '#' + || (c == '-' && (i + 1) < this.statementLength && sql + .charAt(i + 1) == '-')) { + // run out to end of statement, or newline, + // whichever comes first + int endOfStmt = this.statementLength - 1; + + for (; i < endOfStmt; i++) { + c = sql.charAt(i); + + if (c == '\r' || c == '\n') { + break; + } + } + continue; } else if (c == '/' && (i + 1) < this.statementLength) { // Comment? - c = sql.charAt(i + 1); + char cNext = sql.charAt(i + 1); - if (c == '*') { + if (cNext == '*') { i+= 2; for (int j = i; j < this.statementLength; j++) { i++; - c = sql.charAt(j); + cNext = sql.charAt(j); - if (c == '*' && (j + 1) < this.statementLength) { + if (cNext == '*' && (j + 1) < this.statementLength) { if (sql.charAt(j + 1) == '/') { i++; Modified: branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java =================================================================== --- branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2007-06-28 14:29:12 UTC (rev 6470) +++ branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java 2007-06-28 16:18:10 UTC (rev 6471) @@ -4092,4 +4092,61 @@ } } + + /** + * Tests fix for BUG#28851 - parser in client-side prepared statements + * eats character following '/' if it's not a multi-line comment. + * + * @throws Exception if the test fails. + */ + public void testBug28851() throws Exception { + + try { + this.pstmt = ((com.mysql.jdbc.Connection) this.conn) + .clientPrepareStatement("SELECT 1/?"); + this.pstmt.setInt(1, 1); + this.rs = this.pstmt.executeQuery(); + + assertTrue(this.rs.next()); + + assertEquals(1, this.rs.getInt(1)); + } finally { + closeMemberJDBCResources(); + } + } + + /** + * Tests fix for BUG#28596 - parser in client-side prepared statements + * runs to end of statement, rather than end-of-line for '#' comments. + * + * Also added support for '--' single-line comments + * + * @throws Exception if the test fails. + */ + public void testBug28596() throws Exception { + String query = "SELECT #\n" + + "?, #\n" + + "? #?\r\n" + + ",-- abcdefg \n" + + "?"; + + try { + this.pstmt = ((com.mysql.jdbc.Connection) this.conn) + .clientPrepareStatement(query); + this.pstmt.setInt(1, 1); + this.pstmt.setInt(2, 2); + this.pstmt.setInt(3, 3); + + assertEquals(3, this.pstmt.getParameterMetaData().getParameterCount()); + this.rs = this.pstmt.executeQuery(); + + assertTrue(this.rs.next()); + + assertEquals(1, this.rs.getInt(1)); + assertEquals(2, this.rs.getInt(2)); + assertEquals(3, this.rs.getInt(3)); + } finally { + closeMemberJDBCResources(); + } + } } \ No newline at end of file Modified: branches/branch_5_1/connector-j/CHANGES =================================================================== --- branches/branch_5_1/connector-j/CHANGES 2007-06-28 14:29:12 UTC (rev 6470) +++ branches/branch_5_1/connector-j/CHANGES 2007-06-28 16:18:10 UTC (rev 6471) @@ -194,6 +194,14 @@ with version 7), and uses the configuration bundle "coldFusion", which sets useDynamicCharsetInfo to "false" (see previous entry), and sets useLocalSessionState and autoReconnect to "true". + + - Fixed BUG#28851 - parser in client-side prepared statements + eats character following '/' if it's not a multi-line comment. + + - Fixed BUG#28596 - parser in client-side prepared statements + runs to end of statement, rather than end-of-line for '#' comments. + + Also added support for '--' single-line comments. 05-15-07 - Version 5.0.6 Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java =================================================================== --- branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2007-06-28 14:29:12 UTC (rev 6470) +++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2007-06-28 16:18:10 UTC (rev 6471) @@ -268,29 +268,41 @@ quoteChar = 0; } } else { - if (c == '#') { - // run out to end of line - i = this.statementLength - 1; + if (c == '#' + || (c == '-' && (i + 1) < this.statementLength && sql + .charAt(i + 1) == '-')) { + // run out to end of statement, or newline, + // whichever comes first + int endOfStmt = this.statementLength - 1; + + for (; i < endOfStmt; i++) { + c = sql.charAt(i); + + if (c == '\r' || c == '\n') { + break; + } + } + continue; } else if (c == '/' && (i + 1) < this.statementLength) { // Comment? - c = sql.charAt(i + 1); + char cNext = sql.charAt(i + 1); - if (c == '*') { + if (cNext == '*') { i+= 2; for (int j = i; j < this.statementLength; j++) { i++; - c = sql.charAt(j); + cNext = sql.charAt(j); - if (c == '*' && (j + 1) < this.statementLength) { + if (cNext == '*' && (j + 1) < this.statementLength) { if (sql.charAt(j + 1) == '/') { i++; - + if (i < this.statementLength) { c = sql.charAt(i); } - + break; // comment done } } Modified: branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java =================================================================== --- branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java 2007-06-28 14:29:12 UTC (rev 6470) +++ branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java 2007-06-28 16:18:10 UTC (rev 6471) @@ -3972,4 +3972,61 @@ closeMemberJDBCResources(); } } + + /** + * Tests fix for BUG#28851 - parser in client-side prepared statements + * eats character following '/' if it's not a multi-line comment. + * + * @throws Exception if the test fails. + */ + public void testBug28851() throws Exception { + + try { + this.pstmt = ((com.mysql.jdbc.Connection) this.conn) + .clientPrepareStatement("SELECT 1/?"); + this.pstmt.setInt(1, 1); + this.rs = this.pstmt.executeQuery(); + + assertTrue(this.rs.next()); + + assertEquals(1, this.rs.getInt(1)); + } finally { + closeMemberJDBCResources(); + } + } + + /** + * Tests fix for BUG#28596 - parser in client-side prepared statements + * runs to end of statement, rather than end-of-line for '#' comments. + * + * Also added support for '--' single-line comments + * + * @throws Exception if the test fails. + */ + public void testBug28596() throws Exception { + String query = "SELECT #\n" + + "?, #\n" + + "? #?\r\n" + + ",-- abcdefg \n" + + "?"; + + try { + this.pstmt = ((com.mysql.jdbc.Connection) this.conn) + .clientPrepareStatement(query); + this.pstmt.setInt(1, 1); + this.pstmt.setInt(2, 2); + this.pstmt.setInt(3, 3); + + assertEquals(3, this.pstmt.getParameterMetaData().getParameterCount()); + this.rs = this.pstmt.executeQuery(); + + assertTrue(this.rs.next()); + + assertEquals(1, this.rs.getInt(1)); + assertEquals(2, this.rs.getInt(2)); + assertEquals(3, this.rs.getInt(3)); + } finally { + closeMemberJDBCResources(); + } + } }