Bug #71044 | 'commands out of sync' after calling a stored procedure from C-Connector | ||
---|---|---|---|
Submitted: | 1 Dec 2013 9:34 | Modified: | 1 Dec 2013 14:33 |
Reporter: | erick ringot | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: C API (client library) | Severity: | S2 (Serious) |
Version: | 6.0.2 | OS: | Windows (Win 7 - 64 bits) |
Assigned to: | CPU Architecture: | Any | |
Tags: | API, C, out of sync, PROCEDURE, SELECT |
[1 Dec 2013 9:34]
erick ringot
[1 Dec 2013 10:19]
Hartmut Holzgraefe
Not a bug ... A procedure can return more than one result set, and it will always return one extra empty result set that carries some meta information on the procedure call itself, especially error information. You only fetched the results of the SELECT executed within the procedure though. What you actually need to do is to iterate over all returned result sets using mysql_more_results() / mysql_next_result() until all result sets returned by the procedure are consumed. Only then can you send new commands to the server without receiving an "out of sync" error. See also: http://dev.mysql.com/doc/refman/5.6/en/mysql-more-results.html http://dev.mysql.com/doc/refman/5.6/en/mysql-next-result.html
[1 Dec 2013 11:26]
erick ringot
Just adding a call to mysql_next_result() as suggested by Hartmut fixes the problem. See the slightly modified code below : MYSQL_ROW row; MYSQL_RES *res=NULL; char *mycmd="CALL TESTPROC()"; mysql_query(mysql,mycmd); res = mysql_store_result(mysql); while (row = mysql_fetch_row(res)) { ... proceed with row ... } mysql_free_result(res); mysql_next_result(mysql); // <- added instruction // Now subsequent SELECT work This 'bug' (apology, it was not) report can be closed now. Thanks to Hartmut.
[1 Dec 2013 14:33]
MySQL Verification Team
Thanks Hartmut.