diff options
-rw-r--r-- | client/mysqltest.cc | 19 | ||||
-rw-r--r-- | mysql-test/r/insert.result | 40 | ||||
-rw-r--r-- | mysql-test/suite/rpl/r/rpl_udf.result | 8 | ||||
-rw-r--r-- | mysql-test/t/insert.test | 30 | ||||
-rw-r--r-- | sql/sql_table.cc | 2 | ||||
-rw-r--r-- | sql/sql_update.cc | 2 |
6 files changed, 85 insertions, 16 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 48f4b26c69c..4377f944e78 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -6457,8 +6457,6 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, if (!disable_result_log) { - ulonglong UNINIT_VAR(affected_rows); /* Ok to be undef if 'disable_info' is set */ - if (res) { MYSQL_FIELD *fields= mysql_fetch_fields(res); @@ -6475,10 +6473,10 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, /* Need to call mysql_affected_rows() before the "new" - query to find the warnings + query to find the warnings. */ if (!disable_info) - affected_rows= mysql_affected_rows(mysql); + append_info(ds, mysql_affected_rows(mysql), mysql_info(mysql)); /* Add all warnings to the result. We can't do this if we are in @@ -6493,9 +6491,6 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length); } } - - if (!disable_info) - append_info(ds, affected_rows, mysql_info(mysql)); } if (res) @@ -6868,6 +6863,13 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command, */ } + /* + Fetch info before fetching warnings, since it will be reset + otherwise. + */ + if (!disable_info) + append_info(ds, mysql_stmt_affected_rows(stmt), mysql_info(mysql)); + if (!disable_warnings) { /* Get the warnings from execute */ @@ -6891,9 +6893,6 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command, } } - if (!disable_info) - append_info(ds, mysql_affected_rows(mysql), mysql_info(mysql)); - } end: diff --git a/mysql-test/r/insert.result b/mysql-test/r/insert.result index 3f91039d592..f5ad7aee4a9 100644 --- a/mysql-test/r/insert.result +++ b/mysql-test/r/insert.result @@ -639,3 +639,43 @@ CREATE TABLE t2(f1 CHAR(1)); INSERT INTO t2 SELECT f1 FROM t1; DROP TABLE t1, t2; End of 5.0 tests. +# +# Bug#34898 "mysql_info() reports 0 warnings while +# mysql_warning_count() reports 1" +# Check that the number of warnings reported by +# mysql_info() is correct. +# +drop table if exists t1; +create table t1 (data varchar(4) not null); +set sql_mode='error_for_division_by_zero'; +# +# Demonstrate that the number of warnings matches +# the information in mysql_info(). +# +insert t1 (data) values ('letter'), (1/0); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 3 +Warnings: +Warning 1265 Data truncated for column 'data' at row 1 +Warning 1365 Division by 0 +Warning 1048 Column 'data' cannot be null +update t1 set data='envelope' where 1/0 or 1; +affected rows: 2 +info: Rows matched: 2 Changed: 2 Warnings: 3 +Warnings: +Warning 1365 Division by 0 +Warning 1265 Data truncated for column 'data' at row 1 +Warning 1265 Data truncated for column 'data' at row 2 +insert t1 (data) values (default), (1/0), ('dead beef'); +affected rows: 3 +info: Records: 3 Duplicates: 0 Warnings: 4 +Warnings: +Warning 1364 Field 'data' doesn't have a default value +Warning 1365 Division by 0 +Warning 1048 Column 'data' cannot be null +Warning 1265 Data truncated for column 'data' at row 3 +set sql_mode=default; +drop table t1; +# +# End of 5.4 tests +# diff --git a/mysql-test/suite/rpl/r/rpl_udf.result b/mysql-test/suite/rpl/r/rpl_udf.result index ccf16271d01..a6d23b04780 100644 --- a/mysql-test/suite/rpl/r/rpl_udf.result +++ b/mysql-test/suite/rpl/r/rpl_udf.result @@ -181,21 +181,21 @@ affected rows: 2 CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=MyISAM; affected rows: 0 INSERT INTO t1 VALUES(myfunc_int(100), myfunc_double(50.00)); +affected rows: 1 Warnings: Note 1592 Statement may not be safe to log in statement format. -affected rows: 1 INSERT INTO t1 VALUES(myfunc_int(10), myfunc_double(5.00)); +affected rows: 1 Warnings: Note 1592 Statement may not be safe to log in statement format. -affected rows: 1 INSERT INTO t1 VALUES(myfunc_int(200), myfunc_double(25.00)); +affected rows: 1 Warnings: Note 1592 Statement may not be safe to log in statement format. -affected rows: 1 INSERT INTO t1 VALUES(myfunc_int(1), myfunc_double(500.00)); +affected rows: 1 Warnings: Note 1592 Statement may not be safe to log in statement format. -affected rows: 1 SELECT * FROM t1 ORDER BY sum; sum price 1 48.5 diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test index 8f9ed6c7d06..f2b9e61915e 100644 --- a/mysql-test/t/insert.test +++ b/mysql-test/t/insert.test @@ -499,3 +499,33 @@ DROP TABLE t1, t2; --echo End of 5.0 tests. +--echo # +--echo # Bug#34898 "mysql_info() reports 0 warnings while +--echo # mysql_warning_count() reports 1" +--echo # Check that the number of warnings reported by +--echo # mysql_info() is correct. +--echo # + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 (data varchar(4) not null); + +set sql_mode='error_for_division_by_zero'; +--echo # +--echo # Demonstrate that the number of warnings matches +--echo # the information in mysql_info(). +--echo # +--enable_info +insert t1 (data) values ('letter'), (1/0); +update t1 set data='envelope' where 1/0 or 1; +insert t1 (data) values (default), (1/0), ('dead beef'); +--disable_info + +set sql_mode=default; +drop table t1; + +--echo # +--echo # End of 5.4 tests +--echo # diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 2bae6859a83..e6f9bb9e5e3 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7477,7 +7477,7 @@ view_err: end_temporary: my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO), (ulong) (copied + deleted), (ulong) deleted, - (ulong) thd->cuted_fields); + (ulong) thd->warning_info->statement_warn_count()); my_ok(thd, copied + deleted, 0L, tmp_name); thd->some_tables_deleted=0; DBUG_RETURN(FALSE); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index f5c4b85e904..01a66a3a98b 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -833,7 +833,7 @@ int mysql_update(THD *thd, char buff[STRING_BUFFER_USUAL_SIZE]; my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated, - (ulong) thd->warning_info->statement_warn_count()); + (ulong) thd->warning_info->statement_warn_count()); thd->row_count_func= (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated; my_ok(thd, (ulong) thd->row_count_func, id, buff); |