Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-5273

Prepared statement doesn't return metadata after prepare

    Details

    • Type: Bug
    • Status: In Progress
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 10.0.5, 5.5.33a
    • Fix Version/s: 10.1
    • Component/s: None
    • Labels:
    • Environment:
      all platforms

      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
      

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            serg Sergei Golubchik added a comment -

            Is 5.5 affected too?

            Show
            serg Sergei Golubchik added a comment - Is 5.5 affected too?
            Hide
            georg Georg Richter added a comment -

            Yes, 5.5 fails too.

            Show
            georg Georg Richter added a comment - Yes, 5.5 fails too.
            Hide
            holyfoot Alexey Botchkov added a comment -

            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.

            Show
            holyfoot Alexey Botchkov added a comment - 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.

              People

              • Assignee:
                holyfoot Alexey Botchkov
                Reporter:
                georg Georg Richter
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: