[CONC-660] MYSQL_TYPE_BIT column-wise binding crashes Created: 2023-08-14  Updated: 2023-08-18  Resolved: 2023-08-17

Status: Closed
Project: MariaDB Connector/C
Component/s: Prepared Statements
Affects Version/s: 3.3.5
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Sharon He Assignee: Georg Richter
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

MacOS


Attachments: File MYSQL_TYPE_BIT_error.c     File MySQL_TYPE_BIT_test-1.c    

 Description   

This is part of my code, but it crashes during execution. Please let me know if I made any mistake or this is a bug.

MYSQL_BIND bind;
const char *data[]=

{"1","0"}

;

bind.buffer_type = MYSQL_TYPE_BIT;
bind.buffer = data;

mysql_stmt_attr_set(insertStmt, STMT_ATTR_ARRAY_SIZE, &numRows);
mysql_stmt_bind_param(insertStmt, bind);

mysql_stmt_execute(insertStmt);

I also tried the same code except for having
bind.buffer_type = MYSQL_TYPE_STRING;

It did not crash, but I could not fetch the correct data back.



 Comments   
Comment by Georg Richter [ 2023-08-16 ]

Please attach a complete test (including the table definition *and * proper error checking for each API call) which allows us to repeat the problem.

Comment by Sharon He [ 2023-08-16 ]

My apologies. When I have bind.buffer_type=MYSQL_TYPE_BIT; and run mysql_stmt_execute, it doesn't crash, but throws an error:
'No data supplied for parameters in prepared statement.'
Please find the reproduction file in the attachment. MySQL_TYPE_BIT_test-1.c

Comment by Georg Richter [ 2023-08-17 ]

As mentioned in my previous comment, you should always check the return code of API calls. In case there is an error, the program should not continue but handle the error properly.

mysql_stmt_bind_param() should fail, since MYSQL_TYPE_BIT is not supported as parameter type (C doesn't have a bit type), instead use an integer (in your example tinyint).

Comment by Sharon He [ 2023-08-17 ]

I tried bind.buffer_type = MYSQL_TYPE_TINY;
But I still get the error message: Data too long for column 'COL1' at row 1.

Please see the code in the attachment. MYSQL_TYPE_BIT_error.c

Comment by Georg Richter [ 2023-08-18 ]

Hi Sharon,

please note that Jira is an issue tracker, but not a support forum.

You're now getting a completly different error, which is totally unrelated to the initially reported problem, caused by errors in your code.

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