diff options
author | Konstantin Osipov <kostja@sun.com> | 2009-10-16 17:41:43 +0400 |
---|---|---|
committer | Konstantin Osipov <kostja@sun.com> | 2009-10-16 17:41:43 +0400 |
commit | 8441517b52fd7f3b392b451745aeedfb21c0d244 (patch) | |
tree | 7b318b1a8abc8c63ddf2c6db513e6ad1dc58438d | |
parent | efc27b5ffb88c51aa1e21a19506e16f93fddf754 (diff) | |
download | mariadb-git-8441517b52fd7f3b392b451745aeedfb21c0d244.tar.gz |
Backport of 2617.65.4 from 6.0-codebase.
A fix and a test case for Bug#34898 "mysql_info() reports 0 warnings
while mysql_warning_count() reports 1"
Review the patch by Chad Miller, implement review comments
(since Chad left) and push the patch.
This bug is actually not a bug. At least according to Monty.
See Bug#841 "wrong number of warnings" reported back in July 2003
and closed as "not a bug".
mysql_info() was printing the number of truncated columns, not
the number of warnings.
But since the message of mysql_info() was "Warnings: <number of truncated
columns>", people would expect to get the number
of warnings in it, not the number of truncated columns.
So a possible fix would be to change the message of mysql_info()
to say Rows changed: <n>, truncated: <m>.
Instead, put the number of warnings there. That is, remove the
feature that thd->cuted_fields (the number of truncated fields)
is exposed to the client. The number of truncated columns can be
calculated on the client, by analyzing SHOW WARNINGS output,
and in future we may remove thd->cuted_fields altogether.
So let's have one less thing to worry about.
-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); |