Bug #8880 Commands out of sync error with cursors

Submitted: 2 Mar 2005 10:56 Modified: 12 Apr 2005 2:49
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.3 OS:Linux (Linux)
Assigned to: Konstantin Osipov CPU Architecture:Any

[2 Mar 2005 10:56] Georg Richter
Description:
When opening two cursors mysql_stmt_execute reports an "Commands out of sync".
See how to repeat.

Note: the sample works as expected if you add more than one row in tables t1.

How to repeat:
#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>

MYSQL_STMT *stmt1, *stmt2;
MYSQL *mysql;

void die_if(int rc, int line, const char *msg) {
	if (rc) {
		printf("Error in line %d: %s\n", line, msg);
		exit (-1);
	}
}

MYSQL_STMT *open_cursor(char *query) {
	const unsigned long type = CURSOR_TYPE_READ_ONLY;

	MYSQL *stmt =  mysql_stmt_init(mysql);
	die_if(mysql_stmt_prepare(stmt, query, strlen(query)), __LINE__, mysql_stmt_error(stmt));
	die_if(mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void *)&type), __LINE__, mysql_stmt_error(stmt));
	return stmt;
}

int main (int argc, char **argv) {
int rc;
	mysql = mysql_init(NULL);
	mysql_real_connect(mysql, "localhost", "root", "", "test", 0, NULL, 0);

	mysql_query(mysql, "DROP TABLE IF EXISTS t1");
	mysql_query(mysql, "CREATE TABLE t1 (a int not null primary key, b int)");
	mysql_query(mysql, "INSERT INTO t1 VALUES (1,1)");
	/*
	when inserting 2 rows everything works well
	mysql_query(mysql, "INSERT INTO t1 VALUES (1,1),(2,2)");
	*/

	mysql_query(mysql, "DROP TABLE IF EXISTS t2");
	mysql_query(mysql, "CREATE TABLE t2 (a int not null primary key, b int)");
	mysql_query(mysql, "INSERT INTO t2 VALUES (2,2)");

	stmt1 = open_cursor("SELECT a FROM t1");
	stmt2 = open_cursor("SELECT a FROM t2");

	die_if(mysql_stmt_execute(stmt1), __LINE__, mysql_stmt_error(stmt1));
	die_if(mysql_stmt_execute(stmt2), __LINE__, mysql_stmt_error(stmt2));

	mysql_stmt_close(stmt1);
	mysql_stmt_close(stmt2);

	mysql_close(mysql);
}
[23 Mar 2005 15:26] Konstantin Osipov
Subject: bk commit - 5.0 tree (konstantin:1.1829) BUG#9159

ChangeSet
  1.1829 05/03/23 18:01:03 konstantin@mysql.com +5 -0
  Fixes and test cases for Bug#8880 "Commands out of sync error with cursors"
   and Bug#9159 "Server crash during mysql_stmt_close".
  The patch adds support for single-row result sets in cursors.
[24 Mar 2005 14:12] Konstantin Osipov
Pushed into 5.0 tree, which is tagged 5.0.3 (but will go to 5.0.4 most probably).
[12 Apr 2005 2:49] Paul DuBois
Noted in 5.0.4 changelog.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.054 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.