Bug #42490 mysql_stmt_result_metadata incorrectly returns null for some statements
Submitted: 30 Jan 2009 18:55 Modified: 2 Feb 2009 7:08
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Prepared statements Severity:S2 (Serious)
Version:5.1.30, 4.1, 5.0, 5.1, 6.0 bzr OS:Any
Assigned to: CPU Architecture:Any
Tags: mysql_stmt_result_metadata

[30 Jan 2009 18:55] Shane Bester
Description:
mysql_stmt_result_metadata return null for some statements that do indeed return a resultset.

e.g:
optimize table t1;
show processlist;

there might be more statements.

This can confuse client programs, and lead to the client thinking there are no results to fetch, which then may cause 'commands out of sync' problems later.

How to repeat:
attached..

Suggested fix:
return the resultset for metadata for all commands that have a resultset!
[30 Jan 2009 18:56] MySQL Verification Team
testcase

Attachment: bug42490.c (text/plain), 4.53 KiB.

[30 Jan 2009 19:11] MySQL Verification Team
Most, if not all SHOW commands are affected too.  The resultset metadata is shown when those same commands are run in "mysql --column-type-info" mode...
[2 Feb 2009 7:08] Sveta Smirnova
Thank you for the report.

Verified as described.
[6 Mar 2009 8:09] MySQL Verification Team
the more I think about this, the more I wonder if it's not a bug at all, like my explanation at bug #42488 . I'll leave it to somebody else to decide, since I'm evidently confused :)
[27 May 2009 13:59] Andrey Hristov
mysqlnd has this comment, which is based on a comment from libmysql:

/*
  Read metadata only if there is actual result set.
  Beware that SHOW statements bypass the PS framework and thus they send
  no metadata at prepare.
*/
[16 Apr 2013 15:13] Igor Solodovnikov
If it is a bug at all it is not a CAPI bug. The metadata is not generated
inside client library but it is sent from server in the reply to
COM_STMT_PREPARE. Libmysql merely parses this metadata if present (in
cli_read_prepare_result()) and gives it to the user via
mysql_stmt_result_metadata() function.

Thus, if it is decided that after preparing statements like "optimize table
t1" or "show processlist" user should get metadata info from
mysql_stmt_reslut_metadata(), it is enough to send this metadata from server
after COM_STMT_PREPARE commmand. As soon as server sends the metadata,
libmysql will give it to the user.