[CONC-172] Wrong result if bound numeric buffer is bigger than field size Created: 2016-04-12  Updated: 2016-04-24  Resolved: 2016-04-24

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: None
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Lawrin Novitsky Assignee: Georg Richter
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

If to bind , for example, bit(16) field as MYSQL_TYPE_LONG, Connector/C will copy only 2 bytes to the buffer when fetches the row. Thus application can get basically wrong value.

mysql_query(ma, "DROP TABLE IF EXISTS `copying_bug`");
mysql_query(ma, "CREATE TABLE `copying_bug` (`a` bit(16) NOT NULL)");
mysql_query(ma, "INSERT INTO `copying_bug` (`a`) VALUES(0)");

st= mysql_stmt_init(ma);

val= 0xffffffff;

bind.buffer_length= 4;
bind.buffer= &val;
bind.buffer_type= MYSQL_TYPE_LONG;
bind.length= &bind.length_value;
bind.is_null= NULL;
bind.error= NULL;

mysql_stmt_prepare(st, "SELECT a FROM copying_bug", strlen("SELECT a FROM copying_bug");
mysql_stmt_execute(st);

mysql_stmt_bind_result(st, &bind);

mysql_stmt_fetch(st);

printf("Value is: %d, (copied)size is %d\n", val, bind.length_value);

mysql_stmt_close(st);

mysql_query(ma, "DROP TABLE IF EXISTS `copying_bug`");



 Comments   
Comment by Lawrin Novitsky [ 2016-04-12 ]

It may be more like a documentation issue

Comment by Georg Richter [ 2016-04-24 ]

Bit values are returned as strings and require interpretation on client side. For converting a bit column into numeric value use column + 0 or CAST in your select statement.

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