Bug #3223 execute fails with unknown error when binding a negative val to unsigned

Submitted: 18 Mar 2004 6:07 Modified: 18 Apr 2004 9:22
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.2 OS:Any (all)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[18 Mar 2004 6:07] Georg Richter
Description:
When binding a nagative value to an column which is defined as unsigned, mysql_execute returns an "unknown error".

We should fix error message or convert negative number.

How to repeat:
#include <mysql.h>
#include <stdio.h>

int main() {
	MYSQL		*mysql;
	MYSQL_STMT	*stmt;
	char		query[512];
	MYSQL_BIND	bind[1];
	long		my_val = 0L;
	long		my_length = 0L;
	long		my_null = 0L;

	mysql = mysql_init(NULL);
	mysql_real_connect(mysql, "localhost", "root", "", "test", 0, NULL, 0);

	/* create a temporary table */
	mysql_query(mysql, "CREATE TEMPORARY TABLE t1 (c1 int unsigned)");

	/* insert some values */
	mysql_query(mysql, "INSERT INTO t1 VALUES (1),(-1)");

	/* no error */
	if (mysql_errno(mysql)) {
		printf("Error: %s\n", mysql_error(mysql));
	}

	strcpy(query, "INSERT INTO t1 VALUES (?)");

	/* create a prepared statement */
	stmt = mysql_stmt_init(mysql);
	mysql_stmt_prepare(stmt, query, strlen(query));

	/* bind parameters */
	bind[0].buffer_type = FIELD_TYPE_LONG;
	bind[0].buffer = (char *)&my_val;
	bind[0].length = &my_length;
	bind[0].is_null = (char*)&my_null;

	mysql_bind_param(stmt, bind);

	if (mysql_stmt_errno(stmt)) {
		printf("Error (bind_result): %s\n", mysql_stmt_error(stmt));
		mysql_stmt_close(stmt);
		mysql_close(mysql);
		exit (-1);
	}

	my_val = -1;
	mysql_execute(stmt);	

	/* this should throw an unknown error */
	if (mysql_stmt_errno(stmt)) {
		printf("Error (execute): %s\n", mysql_stmt_error(stmt));
	}

	mysql_stmt_close(stmt);
	mysql_close(mysql);
}
[27 Mar 2004 13:47] MySQL Verification Team
Verified against 4.1.2.
Small fix for test case sample:

	/* bind parameters */
	bind[0].buffer_type = FIELD_TYPE_LONG;
	bind[0].buffer = (char *)&my_val;
-       bind[0].length = &my_length;
+       bind[0].length = (ulong*) &my_length;
	bind[0].is_null = (char*)&my_null;
[8 Apr 2004 1:16] Oleksandr Byelkin
ChangeSet 
  1.1782 04/04/08 11:07:37 bell@sanja.is.com.ua +2 -0 
  field->store resuts passing is fixed for REAL and INT for Item_param 
(BUG3223)
[18 Apr 2004 9:22] Oleksandr Byelkin
Thank you for bugreport. Fix for this bug is pushed to our internal source 
repository and vill be present in next server release

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.