MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Konstantin Osipov Date:July 24 2009 2:04pm
Subject:bzr commit into mysql-5.4 branch (kostja:2828) Bug#34898
View as plain text  
#At file:///opt/local/work/5.4-azalea-bugfixing/ based on revid:alik@stripped

 2828 Konstantin Osipov	2009-07-24
      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.
     @ client/mysqltest.cc
        Fix a bug in mysqltest program which used to return 
        a wrong number of affected rows in ps-protocol, and a wrong
        mysql_info() information in both protocols in presence of warnings.
     @ mysql-test/r/insert.result
        Update results (Bug#34898)
     @ mysql-test/t/insert.test
        Add a test case for Bug#34898.
     @ sql/sql_insert.cc
        A fix for Bug#34898 - report statement warn count, not the
        number of truncated values in mysql_info().
     @ sql/sql_load.cc
        A fix for Bug#34898 - report statement warn count, not the
        number of truncated values in mysql_info().
     @ sql/sql_table.cc
        A fix for Bug#34898 - report statement warn count, not the
        number of truncated values in mysql_info().
     @ sql/sql_update.cc
        A fix for Bug#34898 - report statement warn count, not the
        number of truncated values in mysql_info().

    modified:
      client/mysqltest.cc
      mysql-test/r/insert.result
      mysql-test/t/insert.test
      sql/sql_insert.cc
      sql/sql_load.cc
      sql/sql_table.cc
      sql/sql_update.cc
=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2009-07-06 08:38:21 +0000
+++ b/client/mysqltest.cc	2009-07-24 14:04:20 +0000
@@ -6576,9 +6576,6 @@ void run_query_normal(struct st_connecti
 
     if (!disable_result_log)
     {
-      ulonglong affected_rows;    /* Ok to be undef if 'disable_info' is set */
-      LINT_INIT(affected_rows);
-
       if (res)
       {
 	MYSQL_FIELD *fields= mysql_fetch_fields(res);
@@ -6595,10 +6592,10 @@ void run_query_normal(struct st_connecti
 
       /*
         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
@@ -6613,9 +6610,6 @@ void run_query_normal(struct st_connecti
 	  dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
 	}
       }
-
-      if (!disable_info)
-	append_info(ds, affected_rows, mysql_info(mysql));
     }
 
     if (res)
@@ -6988,6 +6982,13 @@ void run_query_stmt(MYSQL *mysql, struct
       */
     }
 
+    /*
+      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 */
@@ -7011,9 +7012,6 @@ void run_query_stmt(MYSQL *mysql, struct
       }
     }
 
-    if (!disable_info)
-      append_info(ds, mysql_affected_rows(mysql), mysql_info(mysql));
-
   }
 
 end:

=== modified file 'mysql-test/r/insert.result'
--- a/mysql-test/r/insert.result	2009-07-21 14:57:51 +0000
+++ b/mysql-test/r/insert.result	2009-07-24 14:04:20 +0000
@@ -631,3 +631,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
+#

=== modified file 'mysql-test/t/insert.test'
--- a/mysql-test/t/insert.test	2009-07-21 14:57:51 +0000
+++ b/mysql-test/t/insert.test	2009-07-24 14:04:20 +0000
@@ -493,3 +493,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 #

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2009-07-03 08:42:46 +0000
+++ b/sql/sql_insert.cc	2009-07-24 14:04:20 +0000
@@ -973,10 +973,12 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
     if (ignore)
       sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
 	      (lock_type == TL_WRITE_DELAYED) ? (ulong) 0 :
-	      (ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
+	      (ulong) (info.records - info.copied),
+              (ulong) thd->warning_info->statement_warn_count());
     else
       sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
-	      (ulong) (info.deleted + updated), (ulong) thd->cuted_fields);
+	      (ulong) (info.deleted + updated),
+              (ulong) thd->warning_info->statement_warn_count());
     thd->row_count_func= info.copied + info.deleted + updated;
     ::my_ok(thd, (ulong) thd->row_count_func, id, buff);
   }
@@ -3330,10 +3332,12 @@ bool select_insert::send_eof()
   char buff[160];
   if (info.ignore)
     sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
-	    (ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
+	    (ulong) (info.records - info.copied),
+            (ulong) thd->warning_info->statement_warn_count());
   else
     sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
-	    (ulong) (info.deleted+info.updated), (ulong) thd->cuted_fields);
+	    (ulong) (info.deleted+info.updated),
+            (ulong) thd->warning_info->statement_warn_count());
   thd->row_count_func= info.copied + info.deleted +
                        ((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
                         info.touched : info.updated);

=== modified file 'sql/sql_load.cc'
--- a/sql/sql_load.cc	2009-06-17 15:26:50 +0000
+++ b/sql/sql_load.cc	2009-07-24 14:04:20 +0000
@@ -541,7 +541,8 @@ int mysql_load(THD *thd,sql_exchange *ex
     goto err;
   }
   sprintf(name, ER(ER_LOAD_INFO), (ulong) info.records, (ulong) info.deleted,
-	  (ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
+	  (ulong) (info.records - info.copied),
+          (ulong) thd->warning_info->statement_warn_count());
 
   if (thd->transaction.stmt.modified_non_trans_table)
     thd->transaction.all.modified_non_trans_table= TRUE;

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-07-10 12:31:32 +0000
+++ b/sql/sql_table.cc	2009-07-24 14:04:20 +0000
@@ -7693,7 +7693,7 @@ end_online:
 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);

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2009-06-18 17:09:01 +0000
+++ b/sql/sql_update.cc	2009-07-24 14:04:20 +0000
@@ -833,8 +833,9 @@ int mysql_update(THD *thd,
   if (error < 0)
   {
     char buff[STRING_BUFFER_USUAL_SIZE];
-    my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
-	    (ulong) thd->cuted_fields);
+    my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found,
+                (ulong) updated,
+                (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);


Attachment: [text/bzr-bundle] bzr/kostja@sun.com-20090724140420-ej3knlf23ui3jsnm.bundle
Thread
bzr commit into mysql-5.4 branch (kostja:2828) Bug#34898Konstantin Osipov24 Jul