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

If prepared CALL statement not closed, it can cause unnecessary "Out of sync" error and connection becomes unusable

    XMLWordPrintable

Details

    • Bug
    • Status: In Progress (View Workflow)
    • Blocker
    • Resolution: Unresolved
    • 3.3, 3.4.0
    • 3.4.4
    • Prepared Statements
    • None

    Description

      It happens on move to the next result on another query. Consider the following code example. Please note the comments in the code

      MYSQL      *ma;
        MYSQL_STMT *stmt, *stmt2;
        const my_bool unselected= '\0';
       
        ma = mysql_init(NULL);
        mysql_optionsv(ma, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (const char*)&unselected);
        if (!mysql_real_connect(ma, "localhost", "root", "root", "test", 3306, NULL, CLIENT_MULTI_STATEMENTS))
        {
          printf("Could not connect: %s\n", mysql_error(ma));
          exit(1);
        }
        else
        {
          printf("Server info %s\nClient info: %s\n",
            mysql_get_server_info(ma), mysql_get_client_info());
        }
       
        mysql_query(ma, "DROP PROCEDURE IF EXISTS p1");
        mysql_query(ma, "CREATE PROCEDURE p1() BEGIN"
                        "  SELECT 1 FROM DUAL; "
                        "END");
       
        stmt= mysql_stmt_init(ma);
       
        FAIL_IF(!stmt, "Could not allocate stmt");
       
        mysql_stmt_prepare(stmt, "CALL p1()", -1);
        mysql_stmt_execute(stmt);
       
        mysql_stmt_store_result(stmt);
        // We've done everything w/ result and skip everything else
        while (mysql_stmt_more_results(stmt)) {
          mysql_stmt_next_result(stmt);
          // state at this moment is MYSQL_STMT_WAITING_USE_OR_STORE. But there is no result,
          // we can't store it. And there is no way to change it
        }
        // Now we are not closing it, for later use. For example it's been put to the cache
        // Using connection freely - we haven't done anything wrong, "nothing is out of sync"
        mysql_query(ma, "DROP PROCEDURE p1");
        mysql_query(ma, "DROP PROCEDURE IF EXISTS p2");
        mysql_query(ma, "CREATE PROCEDURE p2() "
                        "BEGIN "
                        "  SELECT 'Marten' FROM DUAL; "
                        "  SELECT 'Zack' FROM DUAL; "
                        "END");
        stmt2= mysql_stmt_init(ma);
       
        mysql_stmt_prepare(stmt2, "CALL p2()", -1);
        mysql_stmt_execute(stmt2);
       
        mysql_stmt_store_result(stmt2);
       
        // I was initially wrong, this goes thru
        check_stmt_rc(mysql_stmt_next_result(stmt2), stmt2);
        // But we get error"Out of sync" set, if check
        //  check_stmt_rc(mysql_stmt_next_result(stmt2), stmt2);
        check_stmt_rc(mysql_stmt_store_result(stmt2), stmt2);
       
        mysql_stmt_close(stmt2);
        mysql_stmt_close(stmt);
       
        mysql_close(ma);
      

      The problem is caused by fix of the CONC-667. In the madb_reset_stmt call to madb_have_pending_results returns true, because state of the stmt is MYSQL_STMT_WAITING_USE_OR_STORE, and the error "Out of sync" is set. I could not find the way to change the state and prevent the error, that's why I find this issue critical. It's show-stopper for C/ODBC

      Attachments

        Issue Links

          Activity

            People

              georg Georg Richter
              Lawrin Lawrin Novitsky
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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