Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-635

first REPLACE INTO command from a batch is ignored

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 2.2.6
    • N/A
    • batch
    • None

    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.

      Attachments

        Issue Links

          Activity

            diego dupin Diego Dupin added a comment -

            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

            diego dupin Diego Dupin added a comment - 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
            diego dupin Diego Dupin added a comment -

            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.

            diego dupin Diego Dupin added a comment - 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.
            diego dupin Diego Dupin added a comment -

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

            diego dupin Diego Dupin added a comment - closing issue, please subscribe to MDEV-17036 to follow issue

            People

              diego dupin Diego Dupin
              doublep Paul Pogonyshev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.