From eb3a54e6359a96b444aecb283948670da00a973d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Nov 2006 12:21:32 +0300 Subject: BUG#23383: mysql_affected_rows() returns different values than mysql_stmt_affected_rows() The problem was that affected_rows for prepared statement wasn't updated in the client library on the error. The solution is to always update affected_rows, which will be equal to -1 on the error. libmysql/libmysql.c: Update status variables even in the case of an error. Some variables have a defined value on the error (like affected_rows is -1), others are undefined, so updating them won't harm. libmysqld/lib_sql.cc: Update status variables even in the case of an error. Some variables have a defined value on the error (like affected_rows is -1), others are undefined, so updating them won't harm. tests/mysql_client_test.c: Add test for bug#23383: mysql_affected_rows() returns different values than mysql_stmt_affected_rows(). --- libmysql/libmysql.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'libmysql/libmysql.c') diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 91c0b6b8864..a4dc382bc37 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -2496,6 +2496,8 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length) NET *net= &mysql->net; char buff[4 /* size of stmt id */ + 5 /* execution flags */]; + my_bool res; + DBUG_ENTER("execute"); DBUG_PRINT("enter",("packet: %s, length :%d",packet ? packet :" ", length)); @@ -2503,15 +2505,17 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length) int4store(buff, stmt->stmt_id); /* Send stmt id to server */ buff[4]= (char) 0; /* no flags */ int4store(buff+5, 1); /* iteration count */ - if (cli_advanced_command(mysql, COM_EXECUTE, buff, sizeof(buff), - packet, length, 1, NULL) || - (*mysql->methods->read_query_result)(mysql)) + + res= test(cli_advanced_command(mysql, COM_EXECUTE, buff, sizeof(buff), + packet, length, 1, NULL) || + (*mysql->methods->read_query_result)(mysql)); + stmt->affected_rows= mysql->affected_rows; + stmt->insert_id= mysql->insert_id; + if (res) { set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate); DBUG_RETURN(1); } - stmt->affected_rows= mysql->affected_rows; - stmt->insert_id= mysql->insert_id; DBUG_RETURN(0); } -- cgit v1.2.1 From ece6b7e1b94078e7f202f26251f0024e1d458c45 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Nov 2006 21:56:03 +0200 Subject: Fixed compiler warnings Don't assert if my_thread_end() is called twice (common case) client/mysql.cc: Removed not used variables client/mysqldump.c: Fixed compiler warnings client/mysqltest.c: Fixed compiler warnings cmd-line-utils/readline/bind.c: Fixed compiler warnings cmd-line-utils/readline/histfile.c: Fixed compiler warnings extra/replace.c: Fixed compiler warning on windows extra/yassl/taocrypt/include/algebra.hpp: Fixed compiler warnings heap/hp_write.c: Fixed compiler warnings innobase/os/os0file.c: Fixed compiler warnings libmysql/libmysql.c: Call my_end()/my_thread_end last. my_end() calls free_charsets(), which allowed me to move the call myisam/myisampack.c: Fixed compiler warnings myisammrg/myrg_rkey.c: Fixed compiler warnings mysys/my_thr_init.c: More comments Don't assert if my_thread_end() is called twice (common case) ndb/src/mgmapi/mgmapi.cpp: Fixed compiler warnings ndb/src/ndbapi/Ndb.cpp: Fixed compiler warnings ndb/src/ndbapi/NdbScanOperation.cpp: Fixed compiler warnings ndb/src/ndbapi/NdbTransaction.cpp: Fixed compiler warnings ndb/src/ndbapi/Ndblist.cpp: Fixed compiler warnings server-tools/instance-manager/guardian.cc: Removed not used variable server-tools/instance-manager/portability.h: Removed duplicated symbol sql/gen_lex_hash.cc: Fixed compiler warning sql/ha_archive.cc: Fixed compiler warnings sql/ha_ndbcluster.cc: Fixed compiler warnings sql/mysqld.cc: Fixed compiler warnings sql/sql_cache.cc: Fixed compiler warnings Fixed DBUG_PRINT strings to be consistent with 5.1 sql/tztime.cc: Fixed compiler warnings sql/uniques.cc: Fixed compiler warnings --- libmysql/libmysql.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libmysql/libmysql.c') diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 6a592f64e49..8c4eb2279e1 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -175,6 +175,9 @@ void STDCALL mysql_server_end() #ifdef EMBEDDED_LIBRARY end_embedded_server(); #endif + finish_client_errs(); + vio_end(); + /* If library called my_init(), free memory allocated by it */ if (!org_my_init_done) { @@ -185,10 +188,11 @@ void STDCALL mysql_server_end() #endif } else + { + free_charsets(); mysql_thread_end(); - finish_client_errs(); - free_charsets(); - vio_end(); + } + mysql_client_init= org_my_init_done= 0; #ifdef EMBEDDED_SERVER if (stderror_file) -- cgit v1.2.1