From e228b4394610ac63a3224b8eb3490daaf330b2b6 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Tue, 6 Dec 2005 15:50:03 -0800 Subject: [PATCH 1/2] Fix value returned by mysql_warning_count() after fetching a prepared statement that generated a warning. (Bug #15510) --- sql-common/client.c | 2 +- tests/mysql_client_test.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/sql-common/client.c b/sql-common/client.c index 976d59d83a4..4c2debd41ff 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -715,6 +715,7 @@ void free_old_query(MYSQL *mysql) init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ mysql->fields= 0; mysql->field_count= 0; /* For API */ + mysql->warning_count= 0; mysql->info= 0; DBUG_VOID_RETURN; } @@ -2484,7 +2485,6 @@ get_info: DBUG_RETURN(1); mysql->status= MYSQL_STATUS_GET_RESULT; mysql->field_count= (uint) field_count; - mysql->warning_count= 0; DBUG_PRINT("exit",("ok")); DBUG_RETURN(0); } diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index ce732690700..f794ac893ae 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -14590,6 +14590,40 @@ static void test_bug14845() myquery(rc); } + +/* + Bug #15510: mysql_warning_count returns 0 after mysql_stmt_fetch which + should warn +*/ +static void test_bug15510() +{ + MYSQL_STMT *stmt; + MYSQL_RES *res; + int rc; + const char *query= "select 1 from dual where 1/0"; + + myheader("test_bug15510"); + + rc= mysql_query(mysql, "set @@sql_mode='ERROR_FOR_DIVISION_BY_ZERO'"); + myquery(rc); + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, query, strlen(query)); + check_execute(stmt, rc); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + rc= mysql_stmt_fetch(stmt); + DIE_UNLESS(mysql_warning_count(mysql)); + + /* Cleanup */ + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "set @@sql_mode=''"); + myquery(rc); +} + /* Read and parse arguments and MySQL options from my.cnf */ @@ -14849,6 +14883,7 @@ static struct my_tests_st my_tests[]= { { "test_bug13488", test_bug13488 }, { "test_bug13524", test_bug13524 }, { "test_bug14845", test_bug14845 }, + { "test_bug15510", test_bug15510}, { 0, 0 } }; From 56faadcc4234bfb85cd5396f9d54ff2b1171a0dd Mon Sep 17 00:00:00 2001 From: "dlenev@mysql.com" <> Date: Wed, 7 Dec 2005 22:36:13 +0300 Subject: [PATCH 2/2] Fix -ansi -pedantic compilation failure. Fix coding style. --- sql/sql_parse.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 6a453407cd0..dc5237d9b7d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2617,7 +2617,7 @@ mysql_execute_command(THD *thd) goto error; /* purecov: inspected */ thd->enable_slow_log= opt_log_slow_admin_statements; res = mysql_backup_table(thd, first_table); - (TABLE_LIST*) select_lex->table_list.first=first_table; + select_lex->table_list.first= (byte*) first_table; lex->query_tables=all_tables; break; } @@ -2630,7 +2630,7 @@ mysql_execute_command(THD *thd) goto error; /* purecov: inspected */ thd->enable_slow_log= opt_log_slow_admin_statements; res = mysql_restore_table(thd, first_table); - (TABLE_LIST*) select_lex->table_list.first=first_table; + select_lex->table_list.first= (byte*) first_table; lex->query_tables=all_tables; break; } @@ -3134,7 +3134,7 @@ end_with_restore_list: mysql_bin_log.write(&qinfo); } } - (TABLE_LIST*) select_lex->table_list.first=first_table; + select_lex->table_list.first= (byte*) first_table; lex->query_tables=all_tables; break; } @@ -3146,7 +3146,7 @@ end_with_restore_list: goto error; /* purecov: inspected */ thd->enable_slow_log= opt_log_slow_admin_statements; res = mysql_check_table(thd, first_table, &lex->check_opt); - (TABLE_LIST*) select_lex->table_list.first=first_table; + select_lex->table_list.first= (byte*) first_table; lex->query_tables=all_tables; break; } @@ -3168,7 +3168,7 @@ end_with_restore_list: mysql_bin_log.write(&qinfo); } } - (TABLE_LIST*) select_lex->table_list.first=first_table; + select_lex->table_list.first= (byte*) first_table; lex->query_tables=all_tables; break; } @@ -3193,7 +3193,7 @@ end_with_restore_list: mysql_bin_log.write(&qinfo); } } - (TABLE_LIST*) select_lex->table_list.first=first_table; + select_lex->table_list.first= (byte*) first_table; lex->query_tables=all_tables; break; }