summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2004-09-22 15:50:07 +0400
committerunknown <konstantin@mysql.com>2004-09-22 15:50:07 +0400
commitccf52b4fd5bd7ae0a418d22f2758cef345b6afa6 (patch)
treee9e451c78db8c48bfcfbf6943d785f85d1b8a6f8 /tests
parentd594d40d119fd536657be3b1523bd5b48f15fa1e (diff)
downloadmariadb-git-ccf52b4fd5bd7ae0a418d22f2758cef345b6afa6.tar.gz
A fix and test case for Bug#5315 "mysql_change_user() doesn't free
prepared statements." include/hash.h: New declaration for hash_reset() function. The old version was not used. libmysql/client_settings.h: Declaration for mysql_detach_stmt_list(). libmysql/libmysql.c: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": add call to mysql_detach_stmt_list(prepared statements) to mysql_change_user(): all statements are freed by server, so client counterparts need to be marked as not usable. mysys/hash.c: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": implementation of hash_reset(), which frees all hash elements and prepares the hash for reuse. sql-common/client.c: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": implementation of mysql_detach_stmt_list(): zero connection pointer in given statement list, thus marking given statements as not usable. sql/sql_class.cc: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": reset prepared statements map in THD::change_user(). sql/sql_class.h: Fix for bug#5315 "mysql_change_user() doesn't free prepared statements": implementation of Statement_map::reset(). A little cleanup of ~Statement_map(): first empty names_hash, as st_hash has a free function, which will delete statements. tests/client_test.c: A test case for bug #5315 "mysql_change_user() doesn't free prepared statements".
Diffstat (limited to 'tests')
-rw-r--r--tests/client_test.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/client_test.c b/tests/client_test.c
index 0a4d635984d..accefb668a8 100644
--- a/tests/client_test.c
+++ b/tests/client_test.c
@@ -10391,6 +10391,34 @@ static void test_bug5194()
}
+static void test_bug5315()
+{
+ MYSQL_STMT *stmt;
+ const char *stmt_text;
+ int rc;
+
+ myheader("test_bug5315");
+
+ stmt_text= "SELECT 1";
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ DBUG_ASSERT(rc == 0);
+ mysql_change_user(mysql, opt_user, opt_password, current_db);
+ rc= mysql_stmt_execute(stmt);
+ DBUG_ASSERT(rc != 0);
+ if (rc)
+ printf("Got error (as expected):\n%s", mysql_stmt_error(stmt));
+ /* check that connection is OK */
+ mysql_stmt_close(stmt);
+ stmt= mysql_stmt_init(mysql);
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ DBUG_ASSERT(rc == 0);
+ rc= mysql_stmt_execute(stmt);
+ DBUG_ASSERT(rc == 0);
+ mysql_stmt_close(stmt);
+}
+
+
/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -10694,6 +10722,8 @@ int main(int argc, char **argv)
test_bug5399(); /* check that statement id uniquely identifies
statement */
test_bug5194(); /* bulk inserts in prepared mode */
+ test_bug5315(); /* check that mysql_change_user closes all
+ prepared statements */
/*
XXX: PLEASE RUN THIS PROGRAM UNDER VALGRIND AND VERIFY THAT YOUR TEST
DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH.