List:Commits« Previous MessageNext Message »
From:<gshchepa Date:February 5 2008 6:04pm
Subject:bk commit into 5.1 tree (gshchepa:1.2662) BUG#30059
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of gshchepa.  When gshchepa does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-02-05 22:04:08+04:00, gshchepa@stripped +4 -0
  Fixed bug#30059.
  Server handles truncation for assignment of too-long values
  into CHAR/VARCHAR/TEXT columns in a different ways when the
  truncated characters are spaces.
  
  Space truncation processing has been synchronised over
  CHAR/VARCHAR/TEXT columns and strict/non-strict server
  modes: server always sends a truncation note instead of
  a warning or an error.

  mysql-test/r/type_binary.result@stripped, 2008-02-05 21:49:02+04:00, gshchepa@stripped +1 -0
    Updated test case for bug#30059.

  mysql-test/r/warnings.result@stripped, 2008-02-05 21:49:17+04:00, gshchepa@stripped +39 -0
    Added test case for bug#30059.

  mysql-test/t/warnings.test@stripped, 2008-02-05 21:49:31+04:00, gshchepa@stripped +34 -0
    Added test case for bug#30059.

  sql/field.cc@stripped, 2008-02-05 21:49:39+04:00, gshchepa@stripped +31 -42
    Fixed bug#30059.
    The report_data_too_long has been replaced with report_if_important_data
    function definition to synchronize same parts of string Field...::store
    methods.

diff -Nrup a/mysql-test/r/type_binary.result b/mysql-test/r/type_binary.result
--- a/mysql-test/r/type_binary.result	2007-01-10 14:06:17 +04:00
+++ b/mysql-test/r/type_binary.result	2008-02-05 21:49:02 +04:00
@@ -125,6 +125,7 @@ create table t1 (c char(2), vc varchar(2
 insert into t1 values(0x4120, 0x4120);
 insert into t1 values(0x412020, 0x412020);
 Warnings:
+Note	1265	Data truncated for column 'c' at row 1
 Note	1265	Data truncated for column 'vc' at row 1
 drop table t1;
 set @old_sql_mode= @@sql_mode, sql_mode= 'traditional';
diff -Nrup a/mysql-test/r/warnings.result b/mysql-test/r/warnings.result
--- a/mysql-test/r/warnings.result	2008-01-11 05:04:22 +04:00
+++ b/mysql-test/r/warnings.result	2008-02-05 21:49:17 +04:00
@@ -277,3 +277,42 @@ DROP PROCEDURE sp1;
 DROP PROCEDURE sp2;
 DROP PROCEDURE sp3;
 End of 5.0 tests
+create table t1 (c_char char(255), c_varchar varchar(255), c_tinytext tinytext);
+create table t2 (c_tinyblob tinyblob);
+set @c = repeat(' ', 256);
+set @q = repeat('q', 256);
+set sql_mode = '';
+insert into t1 values(@c, @c, @c);
+Warnings:
+Note	1265	Data truncated for column 'c_char' at row 1
+Note	1265	Data truncated for column 'c_varchar' at row 1
+Note	1265	Data truncated for column 'c_tinytext' at row 1
+insert into t2 values(@c);
+Warnings:
+Warning	1265	Data truncated for column 'c_tinyblob' at row 1
+insert into t1 values(@q, @q, @q);
+Warnings:
+Warning	1265	Data truncated for column 'c_char' at row 1
+Warning	1265	Data truncated for column 'c_varchar' at row 1
+Warning	1265	Data truncated for column 'c_tinytext' at row 1
+insert into t2 values(@q);
+Warnings:
+Warning	1265	Data truncated for column 'c_tinyblob' at row 1
+set sql_mode = 'traditional';
+insert into t1 values(@c, @c, @c);
+Warnings:
+Note	1265	Data truncated for column 'c_char' at row 1
+Note	1265	Data truncated for column 'c_varchar' at row 1
+Note	1265	Data truncated for column 'c_tinytext' at row 1
+insert into t2 values(@c);
+ERROR 22001: Data too long for column 'c_tinyblob' at row 1
+insert into t1 values(@q, NULL, NULL);
+ERROR 22001: Data too long for column 'c_char' at row 1
+insert into t1 values(NULL, @q, NULL);
+ERROR 22001: Data too long for column 'c_varchar' at row 1
+insert into t1 values(NULL, NULL, @q);
+ERROR 22001: Data too long for column 'c_tinytext' at row 1
+insert into t2 values(@q);
+ERROR 22001: Data too long for column 'c_tinyblob' at row 1
+drop table t1, t2;
+End of 5.1 tests
diff -Nrup a/mysql-test/t/warnings.test b/mysql-test/t/warnings.test
--- a/mysql-test/t/warnings.test	2008-01-11 05:04:28 +04:00
+++ b/mysql-test/t/warnings.test	2008-02-05 21:49:31 +04:00
@@ -194,3 +194,37 @@ DROP PROCEDURE sp2;
 DROP PROCEDURE sp3;
 
 --echo End of 5.0 tests
+
+#
+# Bug#30059: End-space truncation warnings are inconsistent or incorrect
+#
+
+create table t1 (c_char char(255), c_varchar varchar(255), c_tinytext tinytext);
+create table t2 (c_tinyblob tinyblob); # not affected by bug, for regression testing
+set @c = repeat(' ', 256);
+set @q = repeat('q', 256);
+
+set sql_mode = '';
+
+insert into t1 values(@c, @c, @c);
+insert into t2 values(@c);
+insert into t1 values(@q, @q, @q);
+insert into t2 values(@q);
+
+set sql_mode = 'traditional';
+
+insert into t1 values(@c, @c, @c);
+--error 1406
+insert into t2 values(@c);
+--error 1406
+insert into t1 values(@q, NULL, NULL);
+--error 1406
+insert into t1 values(NULL, @q, NULL);
+--error 1406
+insert into t1 values(NULL, NULL, @q);
+--error 1406
+insert into t2 values(@q);
+
+drop table t1, t2;
+
+--echo End of 5.1 tests
diff -Nrup a/sql/field.cc b/sql/field.cc
--- a/sql/field.cc	2008-01-10 14:46:31 +04:00
+++ b/sql/field.cc	2008-02-05 21:49:39 +04:00
@@ -6326,26 +6326,42 @@ check_string_copy_error(Field_str *field
 }
 
 
-
 /*
-  Send a truncation warning or a truncation error
-  after storing a too long character string info a field.
+  Check if we lost any important data and send a truncation error/warning
 
   SYNOPSIS
-    report_data_too_long()
+    report_if_important_data()
     field                    - Field
+    ptr                      - Truncated rest of string
+    end                      - End of truncated string
 
-  RETURN
-    N/A
+  RETURN VALUES
+    0   - None was truncated (or we don't count cutted fields)
+    2   - Some bytes was truncated
+
+  NOTE
+    Check if we lost any important data (anything in a binary string,
+    or any non-space in others). If only trailing spaces was lost,
+    send a truncation note, otherwise send a truncation error.
 */
 
-inline void
-report_data_too_long(Field_str *field)
+static int
+report_if_important_data(Field_str *field, const char *ptr, const char *end)
 {
-  if (field->table->in_use->abort_on_warning)
-    field->set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
-  else
-    field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
+  if ((ptr < end) && field->table->in_use->count_cuted_fields)
+  {
+    if (test_if_important_data(field->charset(), ptr, end))
+    {
+      if (field->table->in_use->abort_on_warning)
+        field->set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
+      else
+        field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
+    }
+    else /* If we lost only spaces then produce a NOTE, not a WARNING */
+      field->set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
+    return 2;
+  }
+  return 0;
 }
 
 
@@ -6380,19 +6396,7 @@ int Field_string::store(const char *from
                               cannot_convert_error_pos, from + length, cs))
     return 2;
 
-  /*
-    Check if we lost any important data (anything in a binary string,
-    or any non-space in others).
-  */
-  if ((from_end_pos < from + length) && table->in_use->count_cuted_fields)
-  {
-    if (test_if_important_data(field_charset, from_end_pos, from + length))
-    {
-      report_data_too_long(this);
-      return 2;
-    }
-  }
-  return 0;
+  return report_if_important_data(this, from_end_pos, from + length);
 }
 
 
@@ -6970,16 +6974,7 @@ int Field_varstring::store(const char *f
                               cannot_convert_error_pos, from + length, cs))
     return 2;
 
-  // Check if we lost something other than just trailing spaces
-  if ((from_end_pos < from + length) && table->in_use->count_cuted_fields)
-  {
-    if (test_if_important_data(field_charset, from_end_pos, from + length))
-      report_data_too_long(this);
-    else /* If we lost only spaces then produce a NOTE, not a WARNING */
-      set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
-    return 2;
-  }
-  return 0;
+  return report_if_important_data(this, from_end_pos, from + length);
 }
 
 
@@ -7681,13 +7676,7 @@ int Field_blob::store(const char *from,u
                               cannot_convert_error_pos, from + length, cs))
     return 2;
 
-  if (from_end_pos < from + length)
-  {
-    report_data_too_long(this);
-    return 2;
-  }
-
-  return 0;
+  return report_if_important_data(this, from_end_pos, from + length);
 
 oom_error:
   /* Fatal OOM error */
Thread
bk commit into 5.1 tree (gshchepa:1.2662) BUG#30059gshchepa5 Feb