[MDEV-12579] Incorrect arguments to mysqld_stmt_execute when using LOBs Created: 2017-04-24  Updated: 2017-09-26  Resolved: 2017-06-22

Status: Closed
Project: MariaDB Server
Component/s: Prepared Statements
Affects Version/s: 10.2.5
Fix Version/s: 10.2.7

Type: Bug Priority: Major
Reporter: FLAESCH Sebastien Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 0
Labels: None
Environment:

Linux Debian 8.6


Attachments: File MDEV-12579.patch     File mdev12579.c    
Sprint: 10.2.7-1

 Description   

When binding LOBs with MYSQL_TYPE_VAR_STRING or MYSQL_TYPE_LONG_BLOB and providing data with mysql_stmt_send_long_data(), we get the following error:

-1210: Incorrect arguments to mysqld_stmt_execute

The same C code works find with Oracle MySQL client.



 Comments   
Comment by FLAESCH Sebastien [ 2017-04-24 ]

Server debug log:

/opt3/dbs/mdb/10.2/bin/mysqld, Version: 10.2.5-MariaDB-log (MariaDB Server). started with:
Tcp port: 3309  Unix socket: /opt3/dbs/mdb/10.2/data/mysqld.sock
Time                 Id Command    Argument
170424 18:11:11     8 Connect   mdbuser@localhost as anonymous on test1
                    8 Query     SELECT @@version
                    8 Query     SET autocommit=1
                    8 Prepare   set character_set_client = 'utf8'
                    8 Execute   set character_set_client = 'utf8'
                    8 Close stmt
                    8 Prepare   DROP TABLE t601
                    8 Close stmt
                    8 Prepare   CREATE TABLE t601 (k integer,t LONGTEXT,b LONGBLOB,x integer)
                    8 Execute   CREATE TABLE t601 (k integer,t LONGTEXT,b LONGBLOB,x integer)
                    8 Close stmt
                    8 Prepare   insert into t601 VALUES (1,?,NULL,?)
                    8 Long Data
                    8 Long Data
                    8 Long Data
                    8 Close stmt
                    8 Prepare   DROP TABLE t601
                    8 Execute   DROP TABLE t601
                    8 Close stmt
                    8 Quit

Comment by Georg Richter [ 2017-04-25 ]

Hi,

I cannot repeat the bug (for testcase see mdev12579.c) in attachments.
Did you set the buffer_type for first bind element correctly?

Comment by FLAESCH Sebastien [ 2017-04-25 ]

A quick gdb session shows that we set buffer_type at first call of mysql_stmt_bind_param():

1081	    if (mysql_stmt_bind_param(st->hstmt, st->param_bind)) {
(gdb) p *(st->param_bind)
$2 = {length = 0x60c00000af28, is_null = 0x60c00000af30 "", buffer = 0x0, error = 0x0, row_ptr = 0x0, store_param_func = 0x0, fetch_result = 0x0, 
  skip_result = 0x0, buffer_length = 0, offset = 0, length_value = 0, param_number = 0, pack_length = 0, buffer_type = MYSQL_TYPE_VAR_STRING, 
  error_value = 0 '\000', is_unsigned = 0 '\000', long_data_used = 0 '\000', is_null_value = 0 '\000', extension = 0x0}

Anything else I could check?

Is there a way to produce some client API debug log to make sure we use it properly?

I will check with older versions of MariaDB... I am quite sure this code was working find before 10.2.5

Comment by Georg Richter [ 2017-04-25 ]

Ok, it is reproducable when specifying MYSQL_TYPE_VAR_STRING. Works fine with MYSQL_TYPE_STRING, and MYSQL_TYPE_BLOB.

Comment by FLAESCH Sebastien [ 2017-04-25 ]

This is good news.
Please read again my initial description: I wrote that we use MYSQL_TYPE_VAR_STRING / MYSQL_TYPE_LONG_BLOB
I confirm it works better with MYSQL_TYPE_STRING / MYSQL_TYPE_BLOB.
But that's not an option for us: we want to keep the code compatible to MySQL.

Comment by Georg Richter [ 2017-04-25 ]

The bug is in server. Client sends correctly type MYSQL_TYPE_VAR_STRING, server converts it internally to MYSQL_TYPE_VARCHAR

sql_type.cc line 145:

case MYSQL_TYPE_VAR_STRING:  return &type_handler_varchar; // Map to VARCHAR

and afterwards function is_param_long_data_type function fails:

/**
  Check whether this parameter data type is compatible with long data.
  Used to detect whether a long data stream has been supplied to a
  incompatible data type.
*/
inline bool is_param_long_data_type(Item_param *param)
{
  return ((param->field_type() >= MYSQL_TYPE_TINY_BLOB) &&
          (param->field_type() <= MYSQL_TYPE_STRING));
}

Comment by Georg Richter [ 2017-04-26 ]

attached test case passes with MySQL 5.7.15 and MariaDB 10.1.21

Comment by FLAESCH Sebastien [ 2017-05-23 ]

Any news on this one? Was expecting to get a fix in 10.2.6 ...

Comment by Oleksandr Byelkin [ 2017-06-22 ]

revision-id: 1d90a8304bf0983a91044ca451129552388b026d (mariadb-10.2.6-54-g1d90a8304bf)
parent(s): 0992be927e1c686c39c39fe53fc2a7869d55143d
committer: Oleksandr Byelkin
timestamp: 2017-06-22 09:52:02 +0200
message:

MDEV-12579: Incorrect arguments to mysqld_stmt_execute when using LOBs

Parameters can be MYSQL_TYPE_VARCHAR for long data load.

Comment by Oleksandr Byelkin [ 2017-06-22 ]

github branch is bb-10.2-MDEV-12579

Comment by Alexander Barkov [ 2017-06-22 ]

Ok to push! Thanks.

Comment by Oleksandr Byelkin [ 2017-06-22 ]

10.3 has it already fixed, so only test suite should be merged.

Comment by FLAESCH Sebastien [ 2017-09-26 ]

Verified with 10.2.8

Generated at Thu Feb 08 07:58:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.