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

Prepared statement doesn't return metadata after prepare

Details

    • 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

      Attachments

        Activity

          georg Georg Richter created issue -

          Is 5.5 affected too?

          serg Sergei Golubchik added a comment - Is 5.5 affected too?
          serg Sergei Golubchik made changes -
          Field Original Value New Value
          Fix Version/s 10.0.6 [ 13202 ]
          georg Georg Richter added a comment -

          Yes, 5.5 fails too.

          georg Georg Richter added a comment - Yes, 5.5 fails too.
          serg Sergei Golubchik made changes -
          Affects Version/s 5.5.33a [ 13500 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 5.5.34 [ 13700 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 5.5.35 [ 14000 ]
          Fix Version/s 5.5.34 [ 13700 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 10.0.7 [ 14100 ]
          Fix Version/s 10.0.6 [ 13202 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 10.0.8 [ 14200 ]
          Fix Version/s 10.0.7 [ 14100 ]
          serg Sergei Golubchik made changes -
          Assignee Oleksandr Byelkin [ sanja ]
          serg Sergei Golubchik made changes -
          Assignee Oleksandr Byelkin [ sanja ] Alexey Botchkov [ holyfoot ]
          holyfoot Alexey Botchkov made changes -
          Status Open [ 1 ] In Progress [ 3 ]

          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.

          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.
          serg Sergei Golubchik made changes -
          Fix Version/s 5.5.36 [ 14600 ]
          Fix Version/s 5.5.35 [ 14000 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 10.0.9 [ 14400 ]
          Fix Version/s 10.0.8 [ 14200 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 10.1.0 [ 12200 ]
          Fix Version/s 10.0.9 [ 14400 ]
          Fix Version/s 5.5.36 [ 14600 ]
          serg Sergei Golubchik made changes -
          Labels upstream
          serg Sergei Golubchik made changes -
          Priority Major [ 3 ] Minor [ 4 ]
          serg Sergei Golubchik made changes -
          Workflow defaullt [ 29700 ] MariaDB v2 [ 43616 ]
          serg Sergei Golubchik made changes -
          Fix Version/s 10.1 [ 16100 ]
          Fix Version/s 10.1.0 [ 12200 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Workflow MariaDB v2 [ 43616 ] MariaDB v3 [ 61515 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Sprint 10.1.11 [ 30 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Rank Ranked lower

          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.

          holyfoot Alexey Botchkov added a comment - 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.
          holyfoot Alexey Botchkov made changes -
          Assignee Alexey Botchkov [ holyfoot ] Sergei Golubchik [ serg ]
          Status In Progress [ 3 ] In Review [ 10002 ]

          looks good!

          serg Sergei Golubchik added a comment - looks good!
          serg Sergei Golubchik made changes -
          Status In Review [ 10002 ] Stalled [ 10000 ]
          serg Sergei Golubchik made changes -
          Assignee Sergei Golubchik [ serg ] Alexey Botchkov [ holyfoot ]
          holyfoot Alexey Botchkov added a comment - 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
          holyfoot Alexey Botchkov made changes -
          Component/s Prepared Statements [ 10804 ]
          Fix Version/s 10.1.11 [ 21202 ]
          Fix Version/s 10.1 [ 16100 ]
          Resolution Fixed [ 1 ]
          Status Stalled [ 10000 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 61515 ] MariaDB v4 [ 147219 ]

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.