diff options
author | unknown <Sinisa@sinisa.nasamreza.org> | 2004-12-07 19:12:29 +0200 |
---|---|---|
committer | unknown <Sinisa@sinisa.nasamreza.org> | 2004-12-07 19:12:29 +0200 |
commit | 086dc7fdff00ae758b93207208bdee16a9cba93b (patch) | |
tree | d3cca00e8433c3fd7930e0b647643f5218e0ef3f /tests/client_test.c | |
parent | 263f4572f2e4ebf5ff413a8166b0ded56c29aec6 (diff) | |
download | mariadb-git-086dc7fdff00ae758b93207208bdee16a9cba93b.tar.gz |
Fix for a bug #6996
BitKeeper/etc/ignore:
Added analyse.test client/mysqladmin.c to the ignore list
libmysql/libmysql.c:
Fix for a bug #6996
This fix enables that after all rows are read from a buffered result,
mysql_stmt_data_seek(stmt,0) can rewind a counter to the beginning,
so that rows can be re-fetched.
tests/client_test.c:
Addition of a test for fix of the bug #6996 in client_test.c
Diffstat (limited to 'tests/client_test.c')
-rw-r--r-- | tests/client_test.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/client_test.c b/tests/client_test.c index a7fadbd3033..75ce242900a 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -11389,6 +11389,67 @@ static void test_conversion() myquery(rc); } +static void test_rewind(void) +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind; + int rc = 0; + const char *stmt_text; + long unsigned int length=4, Data=0; + my_bool isnull=0; + + myheader("test_rewind"); + + stmt_text= "CREATE TABLE t1 (a int)"; + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + stmt_text= "INSERT INTO t1 VALUES(2),(3),(4)"; + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + + stmt= mysql_stmt_init(mysql); + + stmt_text= "SELECT * FROM t1"; + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); + check_execute(stmt, rc); + + bzero(&bind,sizeof(MYSQL_BIND)); + bind.buffer_type= MYSQL_TYPE_LONG; + bind.buffer= (void *)&Data; /* this buffer won't be altered */ + bind.length= &length; + bind.is_null= &isnull; + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + rc= mysql_stmt_store_result(stmt); + DIE_UNLESS(rc == 0); + + rc= mysql_stmt_bind_result(stmt, &bind); + DIE_UNLESS(rc == 0); + + /* retreive all result sets till we are at the end */ + while(!mysql_stmt_fetch(stmt)) + printf("fetched result:%ld\n", Data); + + DIE_UNLESS(rc != MYSQL_NO_DATA); + + /* seek to the first row */ + mysql_stmt_data_seek(stmt, 0); + + /* now we should be able to fetch the results again */ + /* but mysql_stmt_fetch returns MYSQL_NO_DATA */ + while(!(rc= mysql_stmt_fetch(stmt))) + printf("fetched result after seek:%ld\n", Data); + + DIE_UNLESS(rc == MYSQL_NO_DATA); + + stmt_text= "DROP TABLE t1"; + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + rc= mysql_stmt_free_result(stmt); + rc= mysql_stmt_close(stmt); +} /* Read and parse arguments and MySQL options from my.cnf @@ -11594,6 +11655,7 @@ static struct my_tests_st my_tests[]= { { "test_datetime_ranges", test_datetime_ranges }, { "test_bug4172", test_bug4172 }, { "test_conversion", test_conversion }, + { "test_rewind", test_rewind }, { 0, 0 } }; |