From eb75a7a5e21186fccaefd7503dc2a07da6c7f989 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 7 Feb 2005 15:17:30 -0800 Subject: [PATCH 1/6] Add the zlib .libs directory to LD_LIBRARY_PATH in mysql-test-run.sh, which fixes running the tests when using the bundled zlib. mysql-test/mysql-test-run.sh: Add zlib .libs dir to LD_LIBRARY_PATH --- mysql-test/mysql-test-run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 39d3f0492c2..af432f37868 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -194,8 +194,8 @@ MY_LOG_DIR="$MYSQL_TEST_DIR/var/log" # # Set LD_LIBRARY_PATH if we are using shared libraries # -LD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$LD_LIBRARY_PATH" -DYLD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$DYLD_LIBRARY_PATH" +LD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/zlib/.libs:$LD_LIBRARY_PATH" +DYLD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/zlib/.libs:$DYLD_LIBRARY_PATH" export LD_LIBRARY_PATH DYLD_LIBRARY_PATH MASTER_RUNNING=0 From fca90750dfa0a2bee85a4824aba7c2197d45587c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Feb 2005 14:56:20 +0300 Subject: [PATCH 2/6] A fix and test case for Bug#8330 "mysql_stmt_execute crashes" (libmysql). libmysql/libmysql.c: Fix for bug#8330 "mysql_stmt_execute crashes": we need to bail out from mysql_stmt_execute if mysql->net is occupied with a result set of another statement. Otherwise on the next attempt to use net we get a crash, as it's freed in case of error. tests/mysql_client_test.c: A test case for Bug#8330 "mysql_stmt_execute craches" (libmysql) --- libmysql/libmysql.c | 5 ++++ tests/mysql_client_test.c | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 3d84059e981..24a7fa5f929 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -2467,6 +2467,11 @@ int cli_stmt_execute(MYSQL_STMT *stmt) set_stmt_error(stmt, CR_PARAMS_NOT_BOUND, unknown_sqlstate); DBUG_RETURN(1); } + if (stmt->mysql->status != MYSQL_STATUS_READY) + { + set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); + DBUG_RETURN(1); + } net_clear(net); /* Sets net->write_pos */ /* Reserve place for null-marker bytes */ diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 83f8f6ab143..e4bdd1d350a 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -11532,6 +11533,58 @@ static void test_bug6761(void) myquery(rc); } + +/* Bug#8330 - Bug #8330 mysql_stmt_execute crashes (libmysql) */ + +static void test_bug8330() +{ + const char *stmt_text; + MYSQL_STMT *stmt[2]; + int i, rc; + char *query= "select a,b from t1 where a=?"; + MYSQL_BIND bind[2]; + long lval[2]; + + myheader("test_bug8330"); + + stmt_text= "drop table if exists t1"; + /* in case some previos test failed */ + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + stmt_text= "create table t1 (a int, b int)"; + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + + bzero(bind, sizeof(bind)); + for (i=0; i < 2; i++) + { + stmt[i]= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt[i], query, strlen(query)); + check_execute(stmt[i], rc); + + bind[i].buffer_type= MYSQL_TYPE_LONG; + bind[i].buffer= (void*) &lval[i]; + bind[i].is_null= 0; + mysql_stmt_bind_param(stmt[i], &bind[i]); + } + + rc= mysql_stmt_execute(stmt[0]); + check_execute(stmt[0], rc); + + rc= mysql_stmt_execute(stmt[1]); + DIE_UNLESS(rc && mysql_stmt_errno(stmt[1]) == CR_COMMANDS_OUT_OF_SYNC); + rc= mysql_stmt_execute(stmt[0]); + check_execute(stmt[0], rc); + + mysql_stmt_close(stmt[0]); + mysql_stmt_close(stmt[1]); + + stmt_text= "drop table t1"; + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); +} + + /* Read and parse arguments and MySQL options from my.cnf */ @@ -11739,6 +11792,7 @@ static struct my_tests_st my_tests[]= { { "test_conversion", test_conversion }, { "test_rewind", test_rewind }, { "test_bug6761", test_bug6761 }, + { "test_bug8330", test_bug8330 }, { 0, 0 } }; From a26ce94f7adf0fb992045dfdf9d9401a36a6c31c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Feb 2005 17:41:54 +0300 Subject: [PATCH 3/6] A fix and test case for Bug#7990 "mysql_stmt_close doesn't reset mysql->net.last_error": the solution is to clear MYSQL->net error before performing COM_CLOSE: if the call succeeds, the connection is usable for other statements. More comprehensive fix is to clear MYSQL->net for all recoverable errors at the time they happen, it will be implemented in 5.0 as it introduces incompatibility in behavior. libmysql/libmysql.c: A simple fix for Bug#7990 "mysql_stmt_close doesn't reset mysql->net.last_error" tests/mysql_client_test.c: A test case for Bug#7990 " mysql_stmt_close doesn't reset mysql->net.last_error" --- libmysql/libmysql.c | 17 +++++++++++++++++ tests/mysql_client_test.c | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 24a7fa5f929..76cf5c3913c 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1788,6 +1788,18 @@ static my_bool my_realloc_str(NET *net, ulong length) } +/* Clear possible error statee of struct NET */ + +static void net_clear_error(NET *net) +{ + if (net->last_errno) + { + net->last_errno= 0; + net->last_error[0]= '\0'; + strmov(net->sqlstate, not_error_sqlstate); + } +} + /* Set statement error code, sqlstate, and error message from given errcode and sqlstate. @@ -4512,6 +4524,11 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) if (mysql->unbuffered_fetch_owner == &stmt->unbuffered_fetch_cancelled) mysql->unbuffered_fetch_owner= 0; + /* + Clear NET error state: if the following commands come through + successfully, connection will still be usable for other commands. + */ + net_clear_error(&mysql->net); if (mysql->status != MYSQL_STATUS_READY) { /* diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index e4bdd1d350a..2c7a8fdb635 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -11534,7 +11534,7 @@ static void test_bug6761(void) } -/* Bug#8330 - Bug #8330 mysql_stmt_execute crashes (libmysql) */ +/* Bug#8330 - mysql_stmt_execute crashes (libmysql) */ static void test_bug8330() { @@ -11585,6 +11585,26 @@ static void test_bug8330() } +/* Bug#7990 - mysql_stmt_close doesn't reset mysql->net.last_error */ + +static void test_bug7990() +{ + MYSQL_STMT *stmt; + int rc; + myheader("test_bug7990"); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, "foo", 3); + /* + XXX: the fact that we store errno both in STMT and in + MYSQL is not documented and is subject to change in 5.0 + */ + DIE_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql)); + mysql_stmt_close(stmt); + DIE_UNLESS(!mysql_errno(mysql)); +} + + /* Read and parse arguments and MySQL options from my.cnf */ From bebba9582f8c874018d19c73d28874915c3801bb Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Feb 2005 17:46:27 +0300 Subject: [PATCH 4/6] Fix -ansi -pedantic compilation failure. --- sql/sql_parse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 19dc6b389e3..0a0258465fb 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1310,7 +1310,7 @@ enum enum_mysql_completiontype { SAVEPOINT_NAME_ROLLBACK=2, SAVEPOINT_NAME_RELEASE=4, COMMIT_AND_CHAIN=6, - ROLLBACK_AND_CHAIN=7, + ROLLBACK_AND_CHAIN=7 }; int mysql_endtrans(THD *thd, enum enum_mysql_completiontype completion, From d9039e8718d9268297568bb996f1b0672db94ae4 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Feb 2005 18:24:26 +0300 Subject: [PATCH 5/6] Follow-up for bug#7990 libmysql/libmysql.c: And now put it to the proper place and make it work (Bug#7990) tests/mysql_client_test.c: Enable the test for bug#7990 --- libmysql/libmysql.c | 10 +++++----- tests/mysql_client_test.c | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 76cf5c3913c..9c49c7eb15b 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -4518,17 +4518,17 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) if (mysql) { mysql->stmts= list_delete(mysql->stmts, &stmt->list); + /* + Clear NET error state: if the following commands come through + successfully, connection will still be usable for other commands. + */ + net_clear_error(&mysql->net); if ((int) stmt->state > (int) MYSQL_STMT_INIT_DONE) { char buff[MYSQL_STMT_HEADER]; /* 4 bytes - stmt id */ if (mysql->unbuffered_fetch_owner == &stmt->unbuffered_fetch_cancelled) mysql->unbuffered_fetch_owner= 0; - /* - Clear NET error state: if the following commands come through - successfully, connection will still be usable for other commands. - */ - net_clear_error(&mysql->net); if (mysql->status != MYSQL_STATUS_READY) { /* diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 2c7a8fdb635..14b3ddbf8b2 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -11813,6 +11813,7 @@ static struct my_tests_st my_tests[]= { { "test_rewind", test_rewind }, { "test_bug6761", test_bug6761 }, { "test_bug8330", test_bug8330 }, + { "test_bug7990", test_bug7990 }, { 0, 0 } }; From 86b0dc16d9f7a25653e93c0fc1ad83fa4b78401c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Feb 2005 17:07:14 +0100 Subject: [PATCH 6/6] ndb - adapt old testprg to changes in ndbapi ndb/test/ndbapi/bench/userInterface.h: adapt to changes in ndbapi --- ndb/test/ndbapi/bench/userInterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndb/test/ndbapi/bench/userInterface.h b/ndb/test/ndbapi/bench/userInterface.h index 9e3b6f8f2a5..bad61fcf171 100644 --- a/ndb/test/ndbapi/bench/userInterface.h +++ b/ndb/test/ndbapi/bench/userInterface.h @@ -101,7 +101,7 @@ extern "C" { typedef struct { struct Ndb_cluster_connection* pNCC; struct Ndb * pNDB; - struct NdbConnection * pCurrTrans; + struct NdbTransaction * pCurrTrans; } UserHandle; /***************************************************************