1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

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.


libmysql/libmysql.c:
  If we wanted a cursor, and the server wasn't able to create one,
  buffer all rows on client. Currently this is possible only for
  single row result sets and some SHOW commands.
sql/sql_prepare.cc:
  Properly free resources if there was a request to open a cursor which
  wasn't fullfilled.
  Give error on attempt to open a cursor for a statement not returning
  a result set.
sql/sql_select.h:
  Initialize Item_arena of Cursor object. A case when a cursor object
  is created but not used is possible with single-row result sets.
tests/mysql_client_test.c:
  Test cases for Bug#8880 and Bug#9159
This commit is contained in:
unknown
2005-03-24 15:12:53 +03:00
parent 648d40ea66
commit 3b236b1dfd
4 changed files with 89 additions and 7 deletions

View File

@@ -12740,6 +12740,73 @@ static void test_bug8378()
mysql_close(lmysql);
}
MYSQL_STMT *open_cursor(char *query)
{
int rc;
const ulong type= (ulong)CURSOR_TYPE_READ_ONLY;
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
rc= mysql_stmt_prepare(stmt, query, strlen(query));
check_execute(stmt, rc);
mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type);
return stmt;
}
static void test_bug8880()
{
MYSQL_STMT *stmt_list[2], **stmt;
MYSQL_STMT **stmt_list_end= (MYSQL_STMT**) stmt_list + 2;
int rc;
myheader("test_bug8880");
mysql_query(mysql, "drop table if exists t1");
mysql_query(mysql, "create table t1 (a int not null primary key, b int)");
rc= mysql_query(mysql, "insert into t1 values (1,1)");
myquery(rc); /* one check is enough */
/*
when inserting 2 rows everything works well
mysql_query(mysql, "INSERT INTO t1 VALUES (1,1),(2,2)");
*/
for (stmt= stmt_list; stmt < stmt_list_end; stmt++)
*stmt= open_cursor("select a from t1");
for (stmt= stmt_list; stmt < stmt_list_end; stmt++)
{
rc= mysql_stmt_execute(*stmt);
check_execute(*stmt, rc);
}
for (stmt= stmt_list; stmt < stmt_list_end; stmt++)
mysql_stmt_close(*stmt);
}
static void test_bug9159()
{
MYSQL_STMT *stmt;
int rc;
const char *stmt_text= "select a, b from t1";
const unsigned long type= CURSOR_TYPE_READ_ONLY;
myheader("test_bug9159");
mysql_query(mysql, "drop table if exists t1");
mysql_query(mysql, "create table t1 (a int not null primary key, b int)");
rc= mysql_query(mysql, "insert into t1 values (1,1)");
myquery(rc);
stmt= mysql_stmt_init(mysql);
mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void *)&type);
mysql_stmt_execute(stmt);
mysql_stmt_close(stmt);
rc= mysql_query(mysql, "drop table if exists t1");
myquery(rc);
}
/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -12962,6 +13029,8 @@ static struct my_tests_st my_tests[]= {
{ "test_bug8330", test_bug8330 },
{ "test_bug7990", test_bug7990 },
{ "test_bug8378", test_bug8378 },
{ "test_bug8880", test_bug8880 },
{ "test_bug9159", test_bug9159 },
{ 0, 0 }
};