Bug #44825 libmysql breaks existing client applications
Submitted: 12 May 2009 14:16 Modified: 29 Jul 2009 10:16
Reporter: Andrey Hristov Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S2 (Serious)
Version:6.0.8,5.4 OS:Any
Assigned to: Alexander Nozdrin CPU Architecture:Any

[12 May 2009 14:16] Andrey Hristov
Description:
MySQL 6.0.8 introduces support for INOUT and OUT parameters by sending additional result set with the values before the result set with the SP execution status. This makes the extra results 2, from 1 before. The C-API doesn't encapsulate the details of the protocol and the users know they should expect 1 result set more. Well, with 6.0.8+ they will get additional, unexpected result set, which will looks like a result set but is actually the data of the OUT/INOUT variables. This will be a spurious result set for them. Applications that rely on specific number of result sets returned from the server will break. This BREAKS BC! Affected are the normal protocol and the binary protocol (PS). The INOUT/OUT result set is marked with SERVER_PS_OUT_PARAMS in the server status but already written clients don't know this flag.
Those old applications will think that the OUT/INOUT result set is the status result set and most probably discard it or just find incorrect data. Then, when they decided to run another query, while thinking the wire is clear they will get 2014 - Cannot run this command now...just because one result set hasn't been read.

How to repeat:
You can take the example from and modify it not to use a loop but expect just the number of result sets which the SP returns + 1 for its status. You will get 2014.
 
http://dev.mysql.com/doc/refman/6.0/en/c-api-prepared-call-statements.html

Suggested fix:
Add a server and client capability flag which should be negotiated during the initial handshake. And only if the client sets with mysql_options() this CLIENT flag then the result set should be sent. It should be enabled by default, so new applications can use it, but should be switchable so old applications can easily be modified (with a single mysql_options()) call to have the old behavior.
[13 May 2009 9:34] Sveta Smirnova
Thank you for the report.

With version 6.0 I can not compile run example from the manual: it fails at status = mysql_stmt_execute(stmt); with error " Incorrect arguments to mysql_stmt_execute". If take in account 5.1 fails with " OUT or INOUT argument 2 for routine test.p1 is not a variable or NEW pseudo-variable in BE
[13 May 2009 9:35] Sveta Smirnova
Thank you for the report.

With version 6.0 I can not compile run example from the manual: it fails at status = mysql_stmt_execute(stmt); with error " Incorrect arguments to mysql_stmt_execute". If take in account 5.1 fails with " OUT or INOUT argument 2 for routine test.p1 is not a variable or NEW pseudo-variable in BE
[13 May 2009 9:38] Andrey Hristov
Sveta, can you then file a documentation bug report that the example doesn't work. Which doesn't remove make this report nil.
[13 May 2009 9:45] Sveta Smirnova
Andrey, done: bug #44842
[14 May 2009 7:04] Sveta Smirnova
Thank you for the feedback.

Error which prevented me to run the example exists on Mac only.

Bug verified as described. Test case will be attached.
[14 May 2009 8:14] Sveta Smirnova
test case

Attachment: bug44825.c (text/plain), 11.92 KiB.

[14 May 2009 8:19] Sveta Smirnova
corrected test case

Attachment: bug44825.c (text/plain), 11.93 KiB.

[24 Jul 2009 6:59] Alexander Nozdrin
There is already a flag for this: CLIENT_PS_MULTI_RESULTS.

However it is included in CLIENT_CAPABILITIES set of flags,
so there is no way to turn it off.

A solution may be to add support for this flag
in COM_SET_OPTION server command
(mysql_set_server_option() API function)
[24 Jul 2009 8:12] Konstantin Osipov
The text protocol is not affected.
The binary protocol crashes in 5.1 with stored procedures and multiple result sets. The fact that it now works, but requires a change in the client application is IMHO an improvement.
I believe nothing needs to be done about this bug report until we see some external users complain about the change.
[23 Sep 2009 17:19] Andrey Hristov
It is not just libmysql. I have seen multiple RSets work with 5.1 server, it is the problem in libmysql that it can't work with multiple PS rsets in 5.1 and previous.