Bug #7783 mysql_free_result removes all resultsets (multi statements)
Submitted: 10 Jan 2005 20:02 Modified: 17 Feb 2005 19:59
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.9 + 5.0.3 OS:Any (all)
Assigned to: Jani Tolonen CPU Architecture:Any

[10 Jan 2005 20:02] Georg Richter
Description:
When using mysql_use_result to retrieve resultsets from multi statements, 
mysql_free_result removes subsequent resultsets. 
 
See how to repeat. 
 
If you retrieve the rows via 
while ((row = mysql_fetch_row(result))) it works as expected. 

How to repeat:
#include <stdio.h> 
#include <mysql.h> 
 
int main (int argc, char **argv) { 
	MYSQL *mysql; 
	MYSQL_RES *result; 
	MYSQL_ROW row; 
 
	mysql = mysql_init(NULL); 
	mysql_real_connect(mysql, "localhost", "root", "", "", 0, NULL,  
					CLIENT_MULTI_STATEMENTS); 
 
	mysql_query(mysql, "SELECT 2 FROM DUAL; SELECT 3 FROM DUAL"); 
 
	do { 
		if ((result = mysql_use_result(mysql))) { 
			row = mysql_fetch_row(result); 
			printf("%s\n", row[0]); 
			mysql_free_result(result); 
		}  
	} while (!mysql_next_result(mysql)); 
 
	mysql_close(mysql); 
 

Suggested fix:
fix cli_flush_use_result (client.c)
[17 Feb 2005 19:59] Jani Tolonen
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html