[Commits] 06dac6f23f6: MDEV-10355 Weird error message upon CREATE TABLE with DEFAULT

jacob.mathew at mariadb.com jacob.mathew at mariadb.com
Tue Mar 21 07:34:48 EET 2017


revision-id: 06dac6f23f662d6892fddd47c4566c96a3d044d3 (mariadb-10.2.3-180-g06dac6f23f6)
parent(s): cd53525d7c97a7c2b69873fbbd28982844e3cae3
author: Jacob Mathew
committer: Jacob Mathew
timestamp: 2017-03-20 16:35:31 -0700
message:

MDEV-10355 Weird error message upon CREATE TABLE with DEFAULT

Fixed handling of default values with BETWEEN and temporal functions.
Added test case.

---
 mysql-test/r/func_default_between_temporal.result | 11 +++++
 mysql-test/t/func_default_between_temporal.test   |  7 +++
 sql/item.cc                                       | 55 +++++++++++------------
 sql/item.h                                        | 10 ++---
 4 files changed, 48 insertions(+), 35 deletions(-)

diff --git a/mysql-test/r/func_default_between_temporal.result b/mysql-test/r/func_default_between_temporal.result
new file mode 100644
index 00000000000..a1d11f56d4d
--- /dev/null
+++ b/mysql-test/r/func_default_between_temporal.result
@@ -0,0 +1,11 @@
+CREATE OR REPLACE TABLE t1 ( col INT DEFAULT ( 1 LIKE ( NOW() BETWEEN '2000-01-01' AND '2012-12-12' ) ) );
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `col` int(11) DEFAULT (1 like (current_timestamp() between 2000-01-01 00:00:00 and 2012-12-12 00:00:00))
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES( DEFAULT );
+SELECT * FROM t1;
+col
+0
+DROP TABLE t1;
diff --git a/mysql-test/t/func_default_between_temporal.test b/mysql-test/t/func_default_between_temporal.test
new file mode 100644
index 00000000000..e4c8fbbc358
--- /dev/null
+++ b/mysql-test/t/func_default_between_temporal.test
@@ -0,0 +1,7 @@
+CREATE OR REPLACE TABLE t1 ( col INT DEFAULT ( 1 LIKE ( NOW() BETWEEN '2000-01-01' AND '2012-12-12' ) ) );
+SHOW CREATE TABLE t1;
+
+INSERT INTO t1 VALUES( DEFAULT );
+SELECT * FROM t1;
+
+DROP TABLE t1;
diff --git a/sql/item.cc b/sql/item.cc
index dd2c4fd75a5..5c0afc526f8 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -9378,17 +9378,30 @@ void Item_cache::store(Item *item)
 
 void Item_cache::print(String *str, enum_query_type query_type)
 {
-  if (value_cached)
-  {
-    print_value(str);
-    return;
-  }
-  str->append(STRING_WITH_LEN("<cache>("));
-  if (example)
-    example->print(str, query_type);
-  else
-    Item::print(str, query_type);
-  str->append(')');
+    if ( ( query_type & QT_ITEM_ORIGINAL_FUNC_NULLIF ) &&
+         example && ( example->type() == FUNC_ITEM ) )
+    {
+        // Instead of "cache" or the cached value, print the function name,
+        // which is more meaningful to the end user
+        const char *func_name = ( ( Item_func* ) example )->func_name();
+
+        str->append( func_name );
+        str->append( "()" );
+    }
+    else
+    {
+        if (value_cached)
+        {
+            print_value(str);
+            return;
+        }
+        str->append(STRING_WITH_LEN("<cache>("));
+        if (example)
+            example->print(str, query_type);
+        else
+            Item::print(str, query_type);
+        str->append(')');
+    }
 }
 
 /**
@@ -9478,7 +9491,7 @@ Item *Item_cache_int::convert_to_basic_const_item(THD *thd)
 
 Item_cache_temporal::Item_cache_temporal(THD *thd,
                                          enum_field_types field_type_arg):
-  Item_cache_int(thd, field_type_arg), cached_temporal_item_name(NULL)
+  Item_cache_int(thd, field_type_arg)
 {
   if (mysql_type_to_time_type(Item_cache_temporal::field_type()) ==
                               MYSQL_TIMESTAMP_ERROR)
@@ -9619,24 +9632,6 @@ void Item_cache_temporal::store_packed(longlong val_arg, Item *example_arg)
   value_cached= true;
   value= val_arg;
   null_value= false;
-
-  switch (example_arg->type())
-  {
-    case FUNC_ITEM:
-    {
-      // Instead of "cache", use the actual function name,
-      // which is more meaningful to the end user
-      const char *func_name     = ( ( Item_func* ) example_arg )->func_name();
-      char       *ptr           = ( char* ) current_thd->alloc( strlen( func_name ) + 3 );
-
-      if ( ptr )
-      {
-        strxmov( ptr, func_name, "()", NullS );
-      }
-
-      cached_temporal_item_name = ptr;
-    }
-  }
 }
 
 
diff --git a/sql/item.h b/sql/item.h
index 72b48b5e421..745d0213634 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -5436,7 +5436,6 @@ class Item_cache: public Item_basic_constant,
 
   static Item_cache* get_cache(THD *thd, const Item *item);
   static Item_cache* get_cache(THD *thd, const Item* item, const Item_result type);
-  virtual const char* cached_item_name() const { return "cache"; }
   virtual void keep_array() {}
   virtual void print(String *str, enum_query_type query_type);
   bool eq_def(const Field *field) 
@@ -5449,7 +5448,11 @@ class Item_cache: public Item_basic_constant,
   }
   bool check_vcol_func_processor(void *arg) 
   {
-    return mark_unsupported_function(cached_item_name(), arg, VCOL_IMPOSSIBLE);
+    if ( example )
+    {
+        return example->check_vcol_func_processor( arg );
+    }
+    return mark_unsupported_function("cache", arg, VCOL_IMPOSSIBLE);
   }
   /**
      Check if saved item has a non-NULL value.
@@ -5530,7 +5533,6 @@ class Item_cache_int: public Item_cache
 
 class Item_cache_temporal: public Item_cache_int
 {
-  const char *cached_temporal_item_name;
 public:
   Item_cache_temporal(THD *thd, enum_field_types field_type_arg);
   String* val_str(String *str);
@@ -5553,8 +5555,6 @@ class Item_cache_temporal: public Item_cache_int
   Item *convert_to_basic_const_item(THD *thd);
   Item *get_copy(THD *thd, MEM_ROOT *mem_root)
   { return get_item_copy<Item_cache_temporal>(thd, mem_root, this); }
-  const char *cached_item_name() const
-  { return cached_temporal_item_name ? cached_temporal_item_name : "cache"; }
 };
 
 


More information about the commits mailing list