File tree Expand file tree Collapse file tree 3 files changed +35
-1
lines changed
main/java/org/mariadb/jdbc
test/java/org/mariadb/jdbc/integration Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,7 @@ private boolean executeInternalPreparedBatch() throws SQLException {
117117 && ((isCommandInsert && (conf .useBulkStmts () || conf .useBulkStmtsForInserts ()))
118118 || (!isCommandInsert && conf .useBulkStmts ()))
119119 && batchParameters .size () > 1
120+ && batchParameters .get (0 ).size () > 0
120121 && autoGeneratedKeys != Statement .RETURN_GENERATED_KEYS ) {
121122 executeBatchBulk ();
122123 return isCommandInsert ;
Original file line number Diff line number Diff line change @@ -180,7 +180,8 @@ private boolean executeInternalPreparedBatch() throws SQLException {
180180 checkIfInsertCommand ();
181181 if (((isCommandInsert && (conf .useBulkStmts () || conf .useBulkStmtsForInserts ()))
182182 || (!isCommandInsert && conf .useBulkStmts ()))
183- && autoGeneratedKeys != Statement .RETURN_GENERATED_KEYS ) {
183+ && autoGeneratedKeys != Statement .RETURN_GENERATED_KEYS
184+ && batchParameters .get (0 ).size () > 0 ) {
184185 executeBatchBulk (cmd );
185186 return isCommandInsert ;
186187 } else {
Original file line number Diff line number Diff line change @@ -725,4 +725,36 @@ public String toString() {
725725 return "TimestampCal{" + "val=" + val + ", id=" + id + '}' ;
726726 }
727727 }
728+
729+
730+ @ Test
731+ public void batchWithoutParameter () throws SQLException {
732+ try (Connection con = createCon ("&useServerPrepStmts=false&useBulkStmts=true" )) {
733+ batchWithoutParameter (con );
734+ }
735+ try (Connection con = createCon ("&useServerPrepStmts=true&useBulkStmts=true" )) {
736+ batchWithoutParameter (con );
737+ }
738+ }
739+
740+ private void batchWithoutParameter (Connection con ) throws SQLException {
741+ Assumptions .assumeTrue (isMariaDBServer ());
742+ Statement stmt = con .createStatement ();
743+ stmt .execute ("DROP TABLE IF EXISTS batchWithoutParameter" );
744+ stmt .setFetchSize (3 );
745+ stmt .execute ("CREATE TABLE batchWithoutParameter(val varchar(10))" );
746+ try (PreparedStatement prep =
747+ con .prepareStatement ("INSERT INTO batchWithoutParameter VALUES ('')" )) {
748+ prep .addBatch ();
749+ prep .addBatch ();
750+ prep .addBatch ();
751+ prep .addBatch ();
752+ prep .executeBatch ();
753+
754+ ResultSet rs = stmt .executeQuery ("SELECT count(*) FROM batchWithoutParameter" );
755+ rs .next ();
756+ assertEquals (rs .getInt (1 ), 4 );
757+ }
758+ }
759+
728760}
You can’t perform that action at this time.
0 commit comments