List:Commits« Previous MessageNext Message »
From:mmatthews Date:August 29 2007 2:21pm
Subject:Connector/J commit: r6500 - in branches/branch_5_0/connector-j: . src/com/mysql/jdbc src/testsuite/regression
View as plain text  
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/com/mysql/jdbc/Statement.java
   branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java
Log:
Fixed BUG#30550, executeBatch() would fail with an ArithmeticException
      and/or NullPointerException when the batch had zero members and
      "rewriteBatchedStatements" was set to "true" for the connection.

Modified: branches/branch_5_0/connector-j/CHANGES
===================================================================
--- branches/branch_5_0/connector-j/CHANGES	2007-08-29 14:11:48 UTC (rev 6499)
+++ branches/branch_5_0/connector-j/CHANGES	2007-08-29 14:21:52 UTC (rev 6500)
@@ -1,6 +1,12 @@
 # Changelog
 # $Id$
 
+nn-nn-07 - Version 5.0.8
+
+    - Fixed BUG#30550, executeBatch() would fail with an ArithmeticException
+      and/or NullPointerException when the batch had zero members and
+      "rewriteBatchedStatements" was set to "true" for the connection.
+      
 07-19-07 - Version 5.0.7
 
     - Setting the configuration parameter "useCursorFetch" to "true" for 

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-08-29 14:11:48 UTC (rev 6499)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/PreparedStatement.java	2007-08-29 14:21:52 UTC (rev 6500)
@@ -929,6 +929,10 @@
 		}
 
 		synchronized (this.connection.getMutex()) {
+		    if (this.batchedArgs == null || this.batchedArgs.size() == 0) {
+                return new int[0];
+            }
+		    
 			try {
 				clearWarnings();
 

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java	2007-08-29 14:11:48 UTC (rev 6499)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java	2007-08-29 14:21:52 UTC (rev 6500)
@@ -889,6 +889,10 @@
 		}
 
 		synchronized (locallyScopedConn.getMutex()) {
+		    if (this.batchedArgs == null || this.batchedArgs.size() == 0) {
+		        return new int[0];
+		    }
+		    
 			try {
 				this.retrieveGeneratedKeys = true;
 				

Modified: branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java
===================================================================
--- branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java	2007-08-29 14:11:48 UTC (rev 6499)
+++ branches/branch_5_0/connector-j/src/testsuite/regression/StatementRegressionTest.java	2007-08-29 14:21:52 UTC (rev 6500)
@@ -4149,4 +4149,51 @@
 			closeMemberJDBCResources();
 		}
 	}
+	
+	/**
+	 * Tests fix for BUG#30550 - executeBatch() on an empty
+	 * batch when there are no elements in the batch causes a
+	 * divide-by-zero error when rewriting is enabled.
+	 * 
+	 * @throws Exception if the test fails
+	 */
+	public void testBug30550() throws Exception {
+		createTable("testBug30550", "(field1 int)");
+
+		Connection rewriteConn = getConnectionWithProps("rewriteBatchedStatements=true");
+		PreparedStatement batchPStmt = null;
+		Statement batchStmt = null;
+		
+		try {
+			batchStmt = rewriteConn.createStatement();
+			assertEquals(0, batchStmt.executeBatch().length);
+			
+			batchStmt.addBatch("INSERT INTO testBug30550 VALUES (1)");
+			int[] counts = batchStmt.executeBatch();
+			assertEquals(1, counts.length);
+			assertEquals(1, counts[0]);
+			assertEquals(0, batchStmt.executeBatch().length);
+			
+			batchPStmt = rewriteConn.prepareStatement("INSERT INTO testBug30550 VALUES (?)");
+			batchPStmt.setInt(1, 1);
+			assertEquals(0, batchPStmt.executeBatch().length);
+			batchPStmt.addBatch();
+			counts = batchPStmt.executeBatch();
+			assertEquals(1, counts.length);
+			assertEquals(1, counts[0]);
+			assertEquals(0, batchPStmt.executeBatch().length);
+		} finally {
+			if (batchPStmt != null) {
+				batchPStmt.close();
+			}
+			
+			if (batchStmt != null) {
+				batchStmt.close();
+			}
+			
+			if (rewriteConn != null) {
+				rewriteConn.close();
+			}
+		}
+	}
 }
\ No newline at end of file

Thread
Connector/J commit: r6500 - in branches/branch_5_0/connector-j: . src/com/mysql/jdbc src/testsuite/regressionmmatthews29 Aug