Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-566

Calling stored procedure with CURSOR_TYPE_READ_ONLY causes error "Commands out of sync"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.1.15, 3.2.5
    • Component/s: None
    • Labels:
      None

      Description

      #include <mysql.h>
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
       
      int main(int argc, char **argv)
      {
        unsigned int port= 3306;
        if (argc > 1)
          sscanf(argv[1], "%d", &port);
       
        MYSQL *con = mysql_init(NULL);
       
        if (mysql_real_connect(con, "127.0.0.1", "root", "", "test", port, NULL, 0) == NULL)
        {
          fprintf(stderr,"Can't connect: %s\n",mysql_error(con));
          exit(1);
        }
       
        mysql_query(con,"drop procedure if exists sp");
        mysql_query(con,"create procedure sp() select 1");
       
        MYSQL_STMT *stmt = mysql_stmt_init(con);
        unsigned long cursor = CURSOR_TYPE_READ_ONLY;
        const char* query= "call sp()";
       
        if (mysql_stmt_prepare(stmt,query,strlen(query)))
        {
          fprintf(stderr,"Couldn't prepare: %s\n", mysql_error(con));
          mysql_close(con);
          exit(1);
        }
       
        mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor);
       
        if (mysql_stmt_execute(stmt))
          fprintf(stderr,"Got error: %s\n", mysql_stmt_error(stmt));
       
        mysql_stmt_close(stmt);
        mysql_close(con);
        exit(0);
      }
      

      With libmariadb from recent 10.2-10.6, it fails with

      10.2 ceb40ef4

      Got error: Commands out of sync; you can't run this command now
      

      With libmysqlclient from 10.1 or from MySQL 5.7, it works.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              georg Georg Richter
              Reporter:
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration