[CONJ-635] first REPLACE INTO command from a batch is ignored Created: 2018-08-21  Updated: 2018-08-25  Resolved: 2018-08-22

Status: Closed
Project: MariaDB Connector/J
Component/s: batch
Affects Version/s: 2.2.6
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Paul Pogonyshev Assignee: Diego Dupin
Resolution: Not a Bug Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-17036 BULK with replace doesn't take the fi... Closed

 Description   

When I issue a batch REPLACE INTO statement (i.e. with PreparedStatement.addBatch() / executeBatch()) the very first set of parameters is ignored. This happens regardless of whether it would result in inserting or updating.

E.g. if I prepare `replace into test (id, active) values (?, ?)` with parameter sets (1, true), (2, true) and (3, true), the first one (1, true) is ignored:

  • If there is a row with id=1, its `active` column is not updated;
  • If there is no such row, it is not inserted;
  • For all subsequent parameter sets it works as expected;
  • It is really about the first parameter set, not e.g. the one with lowest `id`; if I reorder them, the one becoming first after reordering is ignored.

Note that other batch commands (INSERT INTO, UPDATE etc.) or REPLACE INTO executed as non-batch statement work as expected.



 Comments   
Comment by Diego Dupin [ 2018-08-22 ]

reproduced with code :

        Statement stmt = sharedConnection.createStatement();
        stmt.execute("CREATE TEMPORARY TABLE test_replace (id int not null primary key, active BOOLEAN)")
        stmt.execute("insert into test_replace values (1, false), (2, false), (3, false)");
 
        try (PreparedStatement preparedStatement = sharedConnection.prepareStatement("replace into test_replace (id, active) values (?, ?)")) {
            preparedStatement.setInt(1, 1);
            preparedStatement.setBoolean(2, true);
            preparedStatement.addBatch();
            preparedStatement.setInt(1, 2);
            preparedStatement.setBoolean(2, true);
            preparedStatement.addBatch();
            preparedStatement.setInt(1, 3);
            preparedStatement.setBoolean(2, true);
            preparedStatement.addBatch();
            preparedStatement.setInt(1, 4);
            preparedStatement.setBoolean(2, true);
            preparedStatement.addBatch();
            preparedStatement.executeBatch();
        }
        ResultSet rs = stmt.executeQuery("SELECT * FROM test_replace");
        while (rs.next()) {
            System.out.println(rs.getInt(1) + " " + rs.getBoolean(2));
        }
        /*
        result is
            1 false !!!!!
            2 true
            3 true
            4 true
         */

Connector send the expected data to server, so i've created issue MDEV-17036 server side

Comment by Diego Dupin [ 2018-08-22 ]

Btw these problem is associate with a protocol addition with server since 10.2 (COM_STMT_BULK_EXECUTE). It's use can be disabled setting the option "useBulkStmts" to false.

Comment by Diego Dupin [ 2018-08-22 ]

closing issue, please subscribe to MDEV-17036 to follow issue

Generated at Thu Feb 08 03:17:12 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.