MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:Jim Winstead Date:November 11 2005 3:08am
Subject:bk commit into 5.0 tree (jimw:1.1964) BUG#14299
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of jimw. When jimw 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
  1.1964 05/11/10 19:07:56 jimw@stripped +3 -0
  Report truncation of spaces when inserting into a BINARY field. (Bug #14299)

  sql/field.cc
    1.291 05/11/10 19:07:52 jimw@stripped +25 -17
    Always report truncation of binary strings, even if it was just spaces.
    (Plus some minor style/comment cleanups.)

  mysql-test/t/type_binary.test
    1.2 05/11/10 19:07:52 jimw@stripped +13 -0
    Add new regression test

  mysql-test/r/type_binary.result
    1.2 05/11/10 19:07:52 jimw@stripped +9 -0
    Add results

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	jimw
# Host:	rama.(none)
# Root:	/home/jimw/my/mysql-5.0-14299

--- 1.290/sql/field.cc	2005-11-08 11:18:05 -08:00
+++ 1.291/sql/field.cc	2005-11-10 19:07:52 -08:00
@@ -5855,44 +5855,52 @@
   char buff[STRING_BUFFER_USUAL_SIZE];
   String tmpstr(buff,sizeof(buff), &my_charset_bin);
   uint copy_length;
-  
+
   /* See the comment for Field_long::store(long long) */
   DBUG_ASSERT(table->in_use == current_thd);
-  
+
   /* Convert character set if necessary */
   if (String::needs_conversion(length, cs, field_charset, &not_used))
-  { 
+  {
     uint conv_errors;
     tmpstr.copy(from, length, cs, field_charset, &conv_errors);
     from= tmpstr.ptr();
-    length=  tmpstr.length();
+    length= tmpstr.length();
     if (conv_errors)
       error= 2;
   }
 
-  /* 
-    Make sure we don't break a multibyte sequence
-    as well as don't copy a malformed data.
-  */
+  /* Make sure we don't break a multibyte sequence or copy malformed data. */
   copy_length= field_charset->cset->well_formed_len(field_charset,
                                                     from,from+length,
                                                     field_length/
                                                     field_charset->mbmaxlen,
                                                     &well_formed_error);
   memcpy(ptr,from,copy_length);
-  if (copy_length < field_length)	// Append spaces if shorter
+
+  /* Append spaces if the string was shorter than the field. */
+  if (copy_length < field_length)
     field_charset->cset->fill(field_charset,ptr+copy_length,
-			      field_length-copy_length,
+                              field_length-copy_length,
                               field_charset->pad_char);
-  
+
+  /*
+    Check if we lost any important data (anything in a binary string,
+    or any non-space in others).
+  */
   if ((copy_length < length) && table->in_use->count_cuted_fields)
-  {					// Check if we loosed some info
-    const char *end=from+length;
-    from+= copy_length;
-    from+= field_charset->cset->scan(field_charset, from, end,
-				     MY_SEQ_SPACES);
-    if (from != end)
+  {
+    if (binary())
       error= 2;
+    else
+    {
+      const char *end=from+length;
+      from+= copy_length;
+      from+= field_charset->cset->scan(field_charset, from, end,
+                                       MY_SEQ_SPACES);
+      if (from != end)
+        error= 2;
+    }
   }
   if (error)
   {

--- 1.1/mysql-test/r/type_binary.result	2005-10-13 07:15:46 -07:00
+++ 1.2/mysql-test/r/type_binary.result	2005-11-10 19:07:52 -08:00
@@ -111,3 +111,12 @@
 count(distinct s1)
 3
 drop table t1;
+create table t1 (a binary(2));
+insert into t1 values (0x4120);
+insert into t1 values (0x412020);
+Warnings:
+Warning	1265	Data truncated for column 'a' at row 1
+drop table t1;
+create table t1 (a char(2));
+insert into t1 values (0x412020);
+drop table t1;

--- 1.1/mysql-test/t/type_binary.test	2005-10-13 07:15:41 -07:00
+++ 1.2/mysql-test/t/type_binary.test	2005-11-10 19:07:52 -08:00
@@ -65,3 +65,16 @@
 select hex(s1) from t1 where s1=0x0100;
 select count(distinct s1) from t1;
 drop table t1;
+
+#
+# Bug #14299: BINARY space truncation should cause warning or error
+# 
+create table t1 (a binary(2));
+insert into t1 values (0x4120);
+insert into t1 values (0x412020);
+drop table t1;
+create table t1 (a char(2));
+insert into t1 values (0x412020);
+drop table t1;
+
+# End of 5.0 tests
Thread
bk commit into 5.0 tree (jimw:1.1964) BUG#14299Jim Winstead11 Nov