diff options
author | unknown <konstantin@mysql.com> | 2005-06-30 16:17:10 +0400 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2005-06-30 16:17:10 +0400 |
commit | ec9ac3fe5c823b6ae7ccb0902c267b811bf732e7 (patch) | |
tree | b91ecb9596611574c3dc8bcfd25af12fca92bfe9 /tests | |
parent | 7a5ec7606d9cf70697484df7c235341bc574b4a0 (diff) | |
download | mariadb-git-ec9ac3fe5c823b6ae7ccb0902c267b811bf732e7.tar.gz |
A fix and a test case for Bug#10794 "mysql_stmt_attr_set no
open cursor after mysql_stmt_execute" + post-review fixes.
The bug was caused by wrong flags in stmt->server_status on the client
side: if there was no cursor, the server didn't send server_status
flags to the client, and the old flags were used to set up the
fetch function of a statement. Consequently, stmt_read_row_from_cursor was
used when there was no cursor. The fix fixes the server to always
send server flags to the client.
include/mysql_com.h:
Update stale comments.
libmysql/libmysql.c:
Remove an extra assignment.
libmysqld/lib_sql.cc:
Update to correspond to the changed signature of send_eof
sql/protocol.cc:
Actual fix for bug#10794: create a function that writes the eof
packet to network and use it from send_fields. We need to send
a full eof packet from send_fields to inform the client about
the cursor status (that there is no cursor in this case).
sql/protocol.h:
Remove an unused parameter for send_eof.
tests/mysql_client_test.c:
A test case for Bug#10794 "mysql_stmt_attr_set no open cursor
after mysql_stmt_execute"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mysql_client_test.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 585763c164d..fa70168d0ef 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -13389,6 +13389,93 @@ static void test_bug10736() myquery(rc); } +/* Bug#10794: cursors, packets out of order */ + +static void test_bug10794() +{ + MYSQL_STMT *stmt, *stmt1; + MYSQL_BIND bind[2]; + char a[21]; + int id_val; + ulong a_len; + int rc; + const char *stmt_text; + int i= 0; + ulong type; + + myheader("test_bug10794"); + + mysql_query(mysql, "drop table if exists t1"); + mysql_query(mysql, "create table t1 (id integer not null primary key," + "name varchar(20) not null)"); + stmt= mysql_stmt_init(mysql); + stmt_text= "insert into t1 (id, name) values (?, ?)"; + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); + check_execute(stmt, rc); + bzero(bind, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= (void*) &id_val; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (void*) a; + bind[1].length= &a_len; + rc= mysql_stmt_bind_param(stmt, bind); + check_execute(stmt, rc); + for (i= 0; i < 34; i++) + { + id_val= (i+1)*10; + sprintf(a, "a%d", i); + a_len= strlen(a); /* safety against broken sprintf */ + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + } + stmt_text= "select name from t1"; + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); + type= (ulong) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + stmt1= mysql_stmt_init(mysql); + mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + bzero(bind, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer= (void*) a; + bind[0].buffer_length= sizeof(a); + bind[0].length= &a_len; + rc= mysql_stmt_bind_result(stmt, bind); + check_execute(stmt, rc); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + rc= mysql_stmt_fetch(stmt); + check_execute(stmt, rc); + if (!opt_silent) + printf("Fetched row from stmt: %s\n", a); + /* Don't optimize: an attribute of the original test case */ + mysql_stmt_free_result(stmt); + mysql_stmt_reset(stmt); + stmt_text= "select name from t1 where id=10"; + rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text)); + check_execute(stmt1, rc); + rc= mysql_stmt_bind_result(stmt1, bind); + check_execute(stmt1, rc); + rc= mysql_stmt_execute(stmt1); + while (1) + { + rc= mysql_stmt_fetch(stmt1); + if (rc == MYSQL_NO_DATA) + { + if (!opt_silent) + printf("End of data in stmt1\n"); + break; + } + check_execute(stmt1, rc); + if (!opt_silent) + printf("Fetched row from stmt1: %s\n", a); + } + mysql_stmt_close(stmt); + mysql_stmt_close(stmt1); + + rc= mysql_query(mysql, "drop table t1"); + myquery(rc); +} + /* Read and parse arguments and MySQL options from my.cnf @@ -13626,6 +13713,7 @@ static struct my_tests_st my_tests[]= { { "test_bug11111", test_bug11111 }, { "test_bug9992", test_bug9992 }, { "test_bug10736", test_bug10736 }, + { "test_bug10794", test_bug10794 }, { 0, 0 } }; |