Reputation: 14471
Environment:
I'm writing code using the MySQL C connector.
The bug:
The second (and all subsequent) calls to fetch data always returns a "Commands out of Sync" "Cannot run this command now" error.
Algorithm:
I prepare an invocation of a stored procedure.
call mysql_stmt_result_metadata() to get t meta data.
Bind the results.
call mysql_stmt_store_result() to buffer the results.
call mysql_stmt_fetch() to get all results.
call mysql_stmt_free_result() when finished.
call mysql_stmt_close();
I modeled my code from this example. The only change I made was calling mysql_stmt_store_result() so I could get the size of the result set before fetching it.
Any suggestions?
Upvotes: 2
Views: 2373
Reputation: 14471
This paragraph gives the clue:
"If your program uses CALL statements to execute stored procedures, the CLIENT_MULTI_RESULTS flag must be enabled. This is because each CALL returns a result to indicate the call status, in addition to any result sets that might be returned by statements executed within the procedure. Because CALL can return multiple results, process them using a loop that calls mysql_next_result() to determine whether there are more results. "
The stored procedure may return only one result set, and have no output parameters, but you will receive many result sets, some identical, and some empty. Using the first result set that's marked as not being output parameters seems to work for me.
Upvotes: 2