[MDEV-17036] BULK with replace doesn't take the first parameter in account Created: 2018-08-22  Updated: 2019-04-25  Resolved: 2019-04-25

Status: Closed
Project: MariaDB Server
Component/s: Protocol
Affects Version/s: 10.2, 10.3
Fix Version/s: 10.2.24, 10.3.15, 10.4.5

Type: Bug Priority: Critical
Reporter: Diego Dupin Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Relates
relates to CONJ-635 first REPLACE INTO command from a bat... Closed

 Description   

When using COM_STMT_BULK_EXECUTE , the first "couple" are not taken in account.

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

expected in database :

            1 true
            2 true
            3 true
            4 true

but is

            1 false
            2 true
            3 true
            4 true

The byte send to server are ok, according to COM_STMT_BULK_EXECUTE protocol :

27 00 00 00 FA 01 00 00  00 80 FF 03 00 01 00 00     '...............
01 00 00 00 00 01 00 02  00 00 00 00 01 00 03 00     ................
00 00 00 01 00 04 00 00  00 00 01                    ...........

(tested with server 10.3.7 and 10.2.14)



 Comments   
Comment by Oleksandr Byelkin [ 2019-04-25 ]

static void test_bulk_replace()
{
  int rc;
  MYSQL_STMT *stmt;
  MYSQL_BIND bind[2];
  MYSQL_ROW  row;
  int        i,
             id[]= {1, 2, 3, 4},
             val[]= {1, 1, 1, 1},
             count= sizeof(id)/sizeof(id[0]);
  MYSQL_RES *result;
 
  rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
  myquery(rc);
  rc= mysql_query(mysql, "CREATE TABLE t1 (id int not null primary key, active int)");
  myquery(rc);
  rc= mysql_query(mysql, "insert into t1 values (1, 0), (2, 0), (3, 0)");
  myquery(rc);
  verify_affected_rows(3);
 
  stmt= mysql_stmt_init(mysql);
  rc= mysql_stmt_prepare(stmt, "replace into t1 (id, active) values (?, ?)", -1);
  check_execute(stmt, rc);
 
  memset(bind, 0, sizeof(bind));
  bind[0].buffer_type = MYSQL_TYPE_LONG;
  bind[0].buffer = (void *)id;
  bind[0].buffer_length = 0;
  bind[1].buffer_type = MYSQL_TYPE_LONG;
  bind[1].buffer = (void *)val;
  bind[1].buffer_length = 0;
 
  mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, (void*)&count);
  rc= mysql_stmt_bind_param(stmt, bind);
  check_execute(stmt, rc);
 
  rc= mysql_stmt_execute(stmt);
  check_execute(stmt, rc);
 
  mysql_stmt_close(stmt);
 
  rc= mysql_query(mysql, "SELECT active FROM t1");
  myquery(rc);
 
  result= mysql_store_result(mysql);
  mytest(result);
 
  i= 0;
  while ((row= mysql_fetch_row(result)))
  {
    i++;
    DIE_IF(atoi(row[0]) != 1);
  }
  DIE_IF(i != 4);
  mysql_free_result(result);
 
  rc= mysql_query(mysql, "DROP TABLE t1");
  myquery(rc);
}

Comment by Diego Dupin [ 2019-04-25 ]

correction tested with java drive (specific issue and test suite)

Generated at Thu Feb 08 08:33:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.