Bug #12001 C API - mysql_next_result()

Submitted: 18 Jul 2005 9:33 Modified: 20 Jul 2005 15:19
Reporter: Sela Lerer Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1 OS:Windows (Windows XP)
Assigned to: Georg Richter CPU Architecture:Any

[18 Jul 2005 9:33] Sela Lerer
Description:
When running multiple queries and the last one fails, the mysql_next_result() returns -1 (which means successfull completion and last result) instead of >0 for error. Queries ran after that, fail.

No problem when the bad query is in the middle.

How to repeat:
const char *multiSQL=
                   "DROP TABLE IF EXISTS test_table;"
                   "CREATE TABLE test_table(id INT);"
                   "INSERT INTO test_table VALUES(10);"
                   "UPDATE test_table SET id=20 WHERE id=10;"
                   "SELECT * FROM test_table;"
                   "INSER INTO non_existent_table VALUES(11);"
		   ;
if(0==mysql_real_query(&conn,multiSQL,(unsigned long)strlen(multiSQL)))
{
	MYSQL_RES *result=NULL;
	if(mysql_field_count(&conn)>0)
	{//Clear result in case there is a result.
		result=mysql_use_result(&conn);
		if(NULL!=result)
			mysql_free_result(result);
	}
	while(1)
	{
		res=mysql_next_result(&conn);
		if(mysql_field_count(&conn)>0)
		{//Clear result in case there's a result.
			result=mysql_use_result(&conn);
			if(NULL!=result)
				mysql_free_result(result);
		}
		if(res>0)
		{
			printf("FAIL\n");
			break;
		}
		else
		{
			printf("OK\n");
			if(res==-1)//last one. Gets in here on ERROR too, why?
			{
				printf("\nLast one :-).");
				break;
			}
		}
	printf("\n");
}//while(1)
else
{
	printf("FAIL\n");
}
[18 Jul 2005 9:38] Sela Lerer
Work around: Just add "SELECT 1" or some other meaningless query to the bunch.
[18 Jul 2005 10:06] Sela Lerer
Works fine without SELECT queries.
[18 Jul 2005 10:45] Vasily Kishkin
Tested on Win 2003 , Microsoft Visual C 7.0. Test case is attached.
[18 Jul 2005 10:45] Vasily Kishkin
Test case

Attachment: test.c (text/plain), 1.77 KiB.

[18 Jul 2005 12:43] Sela Lerer
And Vasily? What happened? :-D
[18 Jul 2005 18:33] Georg Richter
Only affects 4.1 - works ok with libmysql 5.0
[19 Jul 2005 6:19] Sela Lerer
Happens to me with 5.0 library too (sending query to 4.1 server).
[19 Jul 2005 15:32] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/27305
[20 Jul 2005 11:37] Georg Richter
patch pushed into 4.1.14
[20 Jul 2005 15:19] Mike Hillyer
Documented in 4.1.14 changelog.

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

Page generated in 0.058 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.