summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <georg@lmy002.wdf.sap.corp>2005-07-15 14:30:47 +0200
committerunknown <georg@lmy002.wdf.sap.corp>2005-07-15 14:30:47 +0200
commit58f2023cc3b0cac9c5a498307fcde8b00da82d8c (patch)
tree105f8ecab5c2f4717252c2106add0e090806c17a
parentba346ddea1e8feb65be14c8b9df1cb3cd4111990 (diff)
downloadmariadb-git-58f2023cc3b0cac9c5a498307fcde8b00da82d8c.tar.gz
Fix for bug #11037.
When all rows are fetched subsequent calls to mysql_stmt_fetch return now MYSQL_NO_DATA instead of errorcode 1. libmysql/libmysql.c: fix for bug#11037 tests/mysql_client_test.c: added new testcase for bug #11037
-rw-r--r--libmysql/libmysql.c15
-rw-r--r--tests/mysql_client_test.c48
2 files changed, 59 insertions, 4 deletions
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index f622b2d2fb2..097983cbbd3 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -1774,6 +1774,7 @@ static int stmt_read_row_unbuffered(MYSQL_STMT *stmt, unsigned char **row);
static int stmt_read_row_buffered(MYSQL_STMT *stmt, unsigned char **row);
static int stmt_read_row_from_cursor(MYSQL_STMT *stmt, unsigned char **row);
static int stmt_read_row_no_data(MYSQL_STMT *stmt, unsigned char **row);
+static int stmt_read_row_no_result_set(MYSQL_STMT *stmt, unsigned char **row);
/*
This function is used in mysql_stmt_store_result if
@@ -2036,7 +2037,7 @@ mysql_stmt_init(MYSQL *mysql)
stmt->list.data= stmt;
stmt->state= MYSQL_STMT_INIT_DONE;
stmt->mysql= mysql;
- stmt->read_row_func= stmt_read_row_no_data;
+ stmt->read_row_func= stmt_read_row_no_result_set;
stmt->prefetch_rows= DEFAULT_PREFETCH_ROWS;
/* The rest of statement members was bzeroed inside malloc */
@@ -2779,6 +2780,13 @@ static int
stmt_read_row_no_data(MYSQL_STMT *stmt __attribute__((unused)),
unsigned char **row __attribute__((unused)))
{
+ return MYSQL_NO_DATA;
+}
+
+static int
+stmt_read_row_no_result_set(MYSQL_STMT *stmt __attribute__((unused)),
+ unsigned char **row __attribute__((unused)))
+{
set_stmt_error(stmt, CR_NO_RESULT_SET, unknown_sqlstate);
return 1;
}
@@ -4600,7 +4608,8 @@ int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt)
((rc= stmt_fetch_row(stmt, row)) && rc != MYSQL_DATA_TRUNCATED))
{
stmt->state= MYSQL_STMT_PREPARE_DONE; /* XXX: this is buggy */
- stmt->read_row_func= stmt_read_row_no_data;
+ stmt->read_row_func= (rc == MYSQL_NO_DATA) ?
+ stmt_read_row_no_data : stmt_read_row_no_result_set;
}
else
{
@@ -4937,7 +4946,7 @@ static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags)
for (; param < param_end; param++)
param->long_data_used= 0;
}
- stmt->read_row_func= stmt_read_row_no_data;
+ stmt->read_row_func= stmt_read_row_no_result_set;
if (mysql)
{
if ((int) stmt->state > (int) MYSQL_STMT_PREPARE_DONE)
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index a056814a153..010f467c4ad 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -13315,7 +13315,7 @@ static void test_bug9992()
DIE_UNLESS(rc == 1); /* Got errors, as expected */
if (!opt_silent)
- fprintf(stdout, "Got error, sa expected:\n [%d] %s\n",
+ fprintf(stdout, "Got error, as expected:\n [%d] %s\n",
mysql_errno(mysql1), mysql_error(mysql1));
mysql_close(mysql1);
@@ -13705,6 +13705,51 @@ static void test_bug11183()
myquery(rc);
}
+static void test_bug11037()
+{
+ MYSQL_STMT *stmt;
+ int rc;
+ const char *stmt_text;
+
+ myheader("test_bug11037");
+
+ mysql_query(mysql, "drop table if exists t1");
+
+ rc= mysql_query(mysql, "create table t1 (id int not null)");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "insert into t1 values (1)");
+ myquery(rc);
+
+ stmt_text= "select id FROM t1";
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+
+ /* expected error */
+ rc = mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc==1);
+ if (!opt_silent)
+ fprintf(stdout, "Got error, as expected:\n [%d] %s\n",
+ mysql_stmt_errno(stmt), mysql_stmt_error(stmt));
+
+ rc = mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc = mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc==0);
+
+ rc = mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc==MYSQL_NO_DATA);
+
+ rc = mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc==MYSQL_NO_DATA);
+
+ mysql_stmt_close(stmt);
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+
/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -13948,6 +13993,7 @@ static struct my_tests_st my_tests[]= {
{ "test_bug10214", test_bug10214 },
{ "test_bug9735", test_bug9735 },
{ "test_bug11183", test_bug11183 },
+ { "test_bug11037", test_bug11037 },
{ 0, 0 }
};