Commit 8441517b authored by Konstantin Osipov's avatar Konstantin Osipov

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.
parent efc27b5f
...@@ -6457,8 +6457,6 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, ...@@ -6457,8 +6457,6 @@ void run_query_normal(struct st_connection *cn, struct st_command *command,
if (!disable_result_log) if (!disable_result_log)
{ {
ulonglong UNINIT_VAR(affected_rows); /* Ok to be undef if 'disable_info' is set */
if (res) if (res)
{ {
MYSQL_FIELD *fields= mysql_fetch_fields(res); MYSQL_FIELD *fields= mysql_fetch_fields(res);
...@@ -6475,10 +6473,10 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, ...@@ -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" Need to call mysql_affected_rows() before the "new"
query to find the warnings query to find the warnings.
*/ */
if (!disable_info) 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 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, ...@@ -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); dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
} }
} }
if (!disable_info)
append_info(ds, affected_rows, mysql_info(mysql));
} }
if (res) if (res)
...@@ -6868,6 +6863,13 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command, ...@@ -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) if (!disable_warnings)
{ {
/* Get the warnings from execute */ /* Get the warnings from execute */
...@@ -6891,9 +6893,6 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command, ...@@ -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: end:
......
...@@ -639,3 +639,43 @@ CREATE TABLE t2(f1 CHAR(1)); ...@@ -639,3 +639,43 @@ CREATE TABLE t2(f1 CHAR(1));
INSERT INTO t2 SELECT f1 FROM t1; INSERT INTO t2 SELECT f1 FROM t1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
End of 5.0 tests. 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
#
...@@ -181,21 +181,21 @@ affected rows: 2 ...@@ -181,21 +181,21 @@ affected rows: 2
CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=MyISAM; CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=MyISAM;
affected rows: 0 affected rows: 0
INSERT INTO t1 VALUES(myfunc_int(100), myfunc_double(50.00)); INSERT INTO t1 VALUES(myfunc_int(100), myfunc_double(50.00));
affected rows: 1
Warnings: Warnings:
Note 1592 Statement may not be safe to log in statement format. 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)); INSERT INTO t1 VALUES(myfunc_int(10), myfunc_double(5.00));
affected rows: 1
Warnings: Warnings:
Note 1592 Statement may not be safe to log in statement format. 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)); INSERT INTO t1 VALUES(myfunc_int(200), myfunc_double(25.00));
affected rows: 1
Warnings: Warnings:
Note 1592 Statement may not be safe to log in statement format. 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)); INSERT INTO t1 VALUES(myfunc_int(1), myfunc_double(500.00));
affected rows: 1
Warnings: Warnings:
Note 1592 Statement may not be safe to log in statement format. Note 1592 Statement may not be safe to log in statement format.
affected rows: 1
SELECT * FROM t1 ORDER BY sum; SELECT * FROM t1 ORDER BY sum;
sum price sum price
1 48.5 1 48.5
......
...@@ -499,3 +499,33 @@ DROP TABLE t1, t2; ...@@ -499,3 +499,33 @@ DROP TABLE t1, t2;
--echo End of 5.0 tests. --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 #
...@@ -7477,7 +7477,7 @@ view_err: ...@@ -7477,7 +7477,7 @@ view_err:
end_temporary: end_temporary:
my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO), my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
(ulong) (copied + deleted), (ulong) deleted, (ulong) (copied + deleted), (ulong) deleted,
(ulong) thd->cuted_fields); (ulong) thd->warning_info->statement_warn_count());
my_ok(thd, copied + deleted, 0L, tmp_name); my_ok(thd, copied + deleted, 0L, tmp_name);
thd->some_tables_deleted=0; thd->some_tables_deleted=0;
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
......
...@@ -833,7 +833,7 @@ int mysql_update(THD *thd, ...@@ -833,7 +833,7 @@ int mysql_update(THD *thd,
char buff[STRING_BUFFER_USUAL_SIZE]; char buff[STRING_BUFFER_USUAL_SIZE];
my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found, my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found,
(ulong) updated, (ulong) updated,
(ulong) thd->warning_info->statement_warn_count()); (ulong) thd->warning_info->statement_warn_count());
thd->row_count_func= thd->row_count_func=
(thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated; (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
my_ok(thd, (ulong) thd->row_count_func, id, buff); my_ok(thd, (ulong) thd->row_count_func, id, buff);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment