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();
    }
  }
}

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 ( ) ; } } }
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 .
