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

mysql_stmt_fetch error during fetch of stored procedure (with cursor) results

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.2(EOL)
    • 10.2(EOL)
    • Server
    • None
    • Linux/Debian, X64, mariadb-10.3.9-linux-x86_64

    Description

      Hi,

      I've tried to fetch result sets from a stored procedure which using cursors in a business application. The mysql_stmt_fetch reported an error (Unknown with code 0) during the first result set or "Commands out of Sync" with an older library (5.5.0). I've searched for days now to how to get the correct result without success. All other statements are working fine (selects/inserts/deletes, calls to procedures without cursor).

      The applications mysql and HeidiSql are working properly and return the expected results. So the server side seems to be working as expected.

      Here my minimized test set:


      Database:

      CREATE DATABASE demo;
      USE demo;
       
      CREATE TABLE demo (id BIGINT(20) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
       
      DELIMITER //
      CREATE PROCEDURE test1() BEGIN SELECT 1 AS ID; SELECT 2 AS ID; END//
      CREATE PROCEDURE test2() BEGIN DECLARE cur1 CURSOR FOR SELECT id FROM demo; OPEN cur1; CLOSE cur1; SELECT 3 AS ID; SELECT 4 AS ID; END//
      


      The C code is attached (mostly taken from https://dev.mysql.com/doc/refman/5.7/en/c-api-prepared-call-statements.html), compiled with:

      gcc demo.c libmariadb.so -o demo
      


      Expected result:

      Client info: 10.3.6
      Statement: CALL test1()
      Server info: 10.3.9-MariaDB
       Fields: 1
        val[0] = 1;
       Fields: 1
        val[0] = 2;
      Statement: CALL test2()
      Server info: 10.3.9-MariaDB
       Fields: 1
        val[0] = 3;
       Fields: 1
        val[0] = 4;
      


      Actual result:

      Client info: 10.3.6
      Statement: CALL test1()
      Server info: 10.3.9-MariaDB
       Fields: 1
        val[0] = 1;
       Fields: 1
        val[0] = 2;
      Statement: CALL test2()
      Server info: 10.3.9-MariaDB
       Fields: 1
      # Error:  (errno: 0)
      


      I'm pretty sure I'm doing something wrong, but I couldn't figure out what to do. At least the error code is misleading and doesn't help to solve the issue.

      Attachments

        Issue Links

          Activity

            georg Georg Richter added a comment - - edited

            Hmm.. this looks like a server bug:

            When executing CALL test2() server sends in first packet server status flag SERVER_STATUS_CURSOR_EXISTS which indicates that subsequent rows must be fetched from client via COM_STMT_FETCH command until server sets status flag SERVER_STATUS_LAST_ROW_SENT. However this can never work unless all results from the stored procedure are processed.

            See also:

            georg Georg Richter added a comment - - edited Hmm.. this looks like a server bug: When executing CALL test2() server sends in first packet server status flag SERVER_STATUS_CURSOR_EXISTS which indicates that subsequent rows must be fetched from client via COM_STMT_FETCH command until server sets status flag SERVER_STATUS_LAST_ROW_SENT. However this can never work unless all results from the stored procedure are processed. See also: Server status flag

            Thank you very much. Shall I test the workaround in my environments?

            Feyd David Fehrmann added a comment - Thank you very much. Shall I test the workaround in my environments?
            georg Georg Richter added a comment -

            There is already a test in ps_bugs.c which tests the workaround.

            georg Georg Richter added a comment - There is already a test in ps_bugs.c which tests the workaround.

            Okay, thank you.

            Feyd David Fehrmann added a comment - Okay, thank you.
            georg Georg Richter added a comment -

            I added a workaround in Connector/C, but this needs to be fixed also in server.

            For both result sets from call test2() the server sets the status "SERVER_STATUS_CURSOR_EXISTS".

            georg Georg Richter added a comment - I added a workaround in Connector/C, but this needs to be fixed also in server. For both result sets from call test2() the server sets the status "SERVER_STATUS_CURSOR_EXISTS".

            People

              sanja Oleksandr Byelkin
              Feyd David Fehrmann
              Votes:
              0 Vote for this issue
              Watchers:
              6 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.