[MDEV-5273] Prepared statement doesn't return metadata after prepare Created: 2013-11-11  Updated: 2016-01-28  Resolved: 2016-01-28

Status: Closed
Project: MariaDB Server
Component/s: Prepared Statements
Affects Version/s: 10.0.5, 5.5.33a
Fix Version/s: 10.1.11

Type: Bug Priority: Minor
Reporter: Georg Richter Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: upstream
Environment:

all platforms


Sprint: 10.1.11

 Description   

According to the documentation metadata for a prepared statement should be available after preparing the statement: "mysql_stmt_field_count() can be called after you have prepared a statement by invoking mysql_stmt_prepare().".

This doesn't work with all kind pf prepared statements.

How to repeat:

static int test_metadata(MYSQL *mysql)
{
  int rc;
  char *query1= "SELECT 1,2 FROM DUAL";
  char *query2= "SHOW CREATE TABLE test_metadata";
  MYSQL_STMT *stmt= mysql_stmt_init(mysql);
 
  rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_metadata");
  check_mysql_rc(rc, mysql);
 
  rc= mysql_query(mysql, "CREATE TABLE test_metadata (a int)"); 
  check_mysql_rc(rc, mysql);
 
  rc= mysql_stmt_prepare(stmt, query1, strlen(query1));
  check_stmt_rc(rc, stmt);
  diag("Fields in result set after prepare: %u", mysql_stmt_field_count(stmt));
 
  rc= mysql_stmt_prepare(stmt, query2, strlen(query2));
  check_stmt_rc(rc, stmt);
  diag("Fields in result set after prepare: %u", mysql_stmt_field_count(stmt));
 
  rc= mysql_stmt_execute(stmt);
  diag("Fields in result set after execute: %u", mysql_stmt_field_count(stmt));
 
  mysql_stmt_close(stmt);
}

Output:

# Fields in result set after prepare: 2
# Fields in result set after prepare: 0
# Fields in result set after execute: 2



 Comments   
Comment by Sergei Golubchik [ 2013-11-14 ]

Is 5.5 affected too?

Comment by Georg Richter [ 2013-11-14 ]

Yes, 5.5 fails too.

Comment by Alexey Botchkov [ 2014-01-25 ]

This is a problem for a whole lot of SHOW commands. The list of affected includes:
SHOW GRANTS
SHOW CREATE DATABASE
SHOW [MASTER | SLAVE] STATUS
SHOW CREATE [PROCEDURE | FUNCTION]
SHOW [PROCEDURE | FUNCTION] CODE
....
All of these return zero fields after the stmt_prepare.
Shortly speaking these are all the SHOW statemets that aren't implemented using the Inf Schema tables.
The number of fields in them is only defined on the execution stage.

I quess the nice solution for it is to extract the metadata-creation part out of the
functions like mysqld_show_create and execute it on the 'prepare' stage. But it involves a lot of coding too.

Comment by Alexey Botchkov [ 2016-01-26 ]

Fixing patch.
http://lists.askmonty.org/pipermail/commits/2016-January/008867.html

It's for the SHOW CREATE command only. If it's approved, other commands can be easily fixed
same way.

Comment by Sergei Golubchik [ 2016-01-26 ]

looks good!

Comment by Alexey Botchkov [ 2016-01-27 ]

Consequitive fixes:
http://lists.askmonty.org/pipermail/commits/2016-January/008875.html
http://lists.askmonty.org/pipermail/commits/2016-January/008876.html
http://lists.askmonty.org/pipermail/commits/2016-January/008877.html
http://lists.askmonty.org/pipermail/commits/2016-January/008878.html
http://lists.askmonty.org/pipermail/commits/2016-January/008879.html
http://lists.askmonty.org/pipermail/commits/2016-January/008880.html

Generated at Thu Feb 08 07:03:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.