[CONC-566] Calling stored procedure with CURSOR_TYPE_READ_ONLY causes error "Commands out of sync" Created: 2021-09-25  Updated: 2021-11-22  Resolved: 2021-09-25

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: None
Fix Version/s: 3.2.5, 3.1.15

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MXS-3818 Upgrade to Connector-C 3.1.15 Closed

 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.


Generated at Thu Feb 08 03:06:13 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.