List:Internals« Previous MessageNext Message »
From:bar Date:July 13 2005 10:00am
Subject:bk commit into 4.1 tree (bar:1.2327)
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of bar. When bar 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.2327 05/07/13 13:00:17 bar@stripped +5 -0
  ctype_utf8.result:
    adding test case
  sql_table.cc:
    sql_table.cc:
    - do not create a new item when charsets are the same
    - return ER_INVALID_DEFAULT if default value cannot
      be converted into the column character set.
  item.cc:
    - Allow conversion not only to Unicode,
      but also to and from "binary".
    - Adding safe_charset_converter() for Item_num
      and Item_varbinary, returning a fixed const Item.

  mysql-test/r/ctype_utf8.result
    1.58 05/07/13 12:52:55 bar@stripped +4 -0
    adding test case

  mysql-test/t/ctype_utf8.test
    1.58 05/07/13 12:52:53 bar@stripped +9 -0

  sql/sql_table.cc
    1.291 05/07/13 12:52:45 bar@stripped +8 -3
    sql_table.cc:
    - do not create a new item when charsets are the same
    - return ER_INVALID_DEFAULT if default value cannot
      be converted into the column character set.

  sql/item.cc
    1.211 05/07/13 12:52:32 bar@stripped +43 -1
    - Allow conversion not only to Unicode,
      but also to and from "binary".
    - Adding safe_charset_converter() for Item_num
      and Item_varbinary, returning a fixed const Item.

  sql/item.h
    1.186 05/07/13 12:52:16 bar@stripped +2 -0

# 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:	bar
# Host:	bar.intranet.mysql.r18.ru
# Root:	/usr/home/bar/mysql-4.1.num-conv

--- 1.210/sql/item.cc	2005-06-27 18:46:35 +05:00
+++ 1.211/sql/item.cc	2005-07-13 12:52:32 +05:00
@@ -212,15 +212,43 @@
 Item *Item::safe_charset_converter(CHARSET_INFO *tocs)
 {
   /*
+    Allow conversion from and to "binary".
     Don't allow automatic conversion to non-Unicode charsets,
     as it potentially loses data.
   */
-  if (!(tocs->state & MY_CS_UNICODE))
+  if (collation.collation != &my_charset_bin &&
+      tocs != &my_charset_bin &&
+      !(tocs->state & MY_CS_UNICODE))
     return NULL; // safe conversion is not possible
   return new Item_func_conv_charset(this, tocs);
 }
 
 
+/*
+  Created mostly for mysql_prepare_table(). Important
+  when a string ENUM/SET column is described with a numeric default value:
+
+  CREATE TABLE t1(a SET('a') DEFAULT 1);
+
+  We cannot use generic Item::safe_charset_converter(), because
+  the latter returns a non-fixed Item, so val_str() crashes afterwards.
+  Override Item_num method, to return a fixed item.
+*/
+Item *Item_num::safe_charset_converter(CHARSET_INFO *tocs)
+{
+  Item_string *conv;
+  char buf[64];
+  String *s, tmp(buf, sizeof(buf), &my_charset_bin);
+  s= val_str(&tmp);
+  if ((conv= new Item_string(s->ptr(), s->length(), s->charset())))
+  {
+    conv->str_value.copy();
+    conv->str_value.shrink_to_length();
+  }
+  return conv;
+}
+
+
 Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs)
 {
   Item_string *conv;
@@ -2150,6 +2178,20 @@
   }
   return FALSE;
 }
+
+
+Item *Item_varbinary::safe_charset_converter(CHARSET_INFO *tocs)
+{
+  Item_string *conv;
+  String tmp, *str= val_str(&tmp);
+
+  if (!(conv= new Item_string(str->ptr(), str->length(), tocs)))
+    return NULL;
+  conv->str_value.copy();
+  conv->str_value.shrink_to_length();
+  return conv;
+}
+
 
 /*
   Pack data in buffer for sending

--- 1.185/sql/item.h	2005-06-27 18:46:35 +05:00
+++ 1.186/sql/item.h	2005-07-13 12:52:16 +05:00
@@ -334,6 +334,7 @@
 {
 public:
   virtual Item_num *neg()= 0;
+  Item *safe_charset_converter(CHARSET_INFO *tocs);
 };
 
 #define NO_CACHED_FIELD_INDEX ((uint)(-1))
@@ -835,6 +836,7 @@
   // to prevent drop fixed flag (no need parent cleanup call)
   void cleanup() {}
   bool eq(const Item *item, bool binary_cmp) const;
+  virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
 };
 
 

--- 1.290/sql/sql_table.cc	2005-06-27 22:30:54 +05:00
+++ 1.291/sql/sql_table.cc	2005-07-13 12:52:45 +05:00
@@ -557,10 +557,15 @@
         Convert the default value from client character
         set into the column character set if necessary.
       */
-      if (sql_field->def)
+      if (sql_field->def && cs != sql_field->def->collation.collation)
       {
-        sql_field->def= 
-          sql_field->def->safe_charset_converter(cs);
+        if (!(sql_field->def= 
+              sql_field->def->safe_charset_converter(cs)))
+        {
+          /* Could not convert */
+          my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
+          DBUG_RETURN(-1);
+        }
       }
 
       if (sql_field->sql_type == FIELD_TYPE_SET)

--- 1.57/mysql-test/r/ctype_utf8.result	2005-06-28 14:59:15 +05:00
+++ 1.58/mysql-test/r/ctype_utf8.result	2005-07-13 12:52:55 +05:00
@@ -905,6 +905,10 @@
 id	city
 2	Durban
 drop table t1;
+create table t1 (x set('A', 'B') default 0) character set utf8;
+ERROR 42000: Invalid default value for 'x'
+create table t1 (x enum('A', 'B') default 0) character set utf8;
+ERROR 42000: Invalid default value for 'x'
 SET NAMES UTF8;
 CREATE TABLE t1 (
 `id` int(20) NOT NULL auto_increment,

--- 1.57/mysql-test/t/ctype_utf8.test	2005-06-28 14:59:04 +05:00
+++ 1.58/mysql-test/t/ctype_utf8.test	2005-07-13 12:52:53 +05:00
@@ -748,6 +748,15 @@
 drop table t1;
 
 #
+# Bug #11819 CREATE TABLE with a SET DEFAULT 0 and UTF8 crashes server.
+#
+--error 1067
+create table t1 (x set('A', 'B') default 0) character set utf8;
+--error 1067
+create table t1 (x enum('A', 'B') default 0) character set utf8;
+
+
+#
 # Test for bug #11167: join for utf8 varchar value longer than 255 bytes 
 #
 
Thread
bk commit into 4.1 tree (bar:1.2327)bar13 Jul