summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Fischer <df@sun.com>2009-04-30 12:45:37 +0200
committerDaniel Fischer <df@sun.com>2009-04-30 12:45:37 +0200
commit195ea7ea9de0ff1027824b71bdab9604ba896e5b (patch)
tree93e874515bf0d719a4d06e548b26de29a056355e
parent3aabe4eb605f15fa361206eb6fa5b8236b4f641f (diff)
downloadmariadb-git-195ea7ea9de0ff1027824b71bdab9604ba896e5b.tar.gz
backport #42014, commit 65523
-rw-r--r--mysql-test/r/func_misc.result5
-rw-r--r--mysql-test/t/func_misc.test9
-rw-r--r--sql/item.cc25
3 files changed, 33 insertions, 6 deletions
diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result
index ce177b511b9..e57d46c006a 100644
--- a/mysql-test/r/func_misc.result
+++ b/mysql-test/r/func_misc.result
@@ -319,4 +319,9 @@ select @my_uuid_date - @my_uuid_synthetic;
@my_uuid_date - @my_uuid_synthetic
0
set @@session.time_zone=@save_tz;
+CREATE TABLE t1 (a DATE);
+SELECT * FROM t1 WHERE a = NAME_CONST('reportDate',
+_binary'2009-01-09' COLLATE 'binary');
+a
+DROP TABLE t1;
End of 5.0 tests
diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test
index 93fe94ec94f..c8075c42fc7 100644
--- a/mysql-test/t/func_misc.test
+++ b/mysql-test/t/func_misc.test
@@ -436,5 +436,14 @@ select @my_uuid_date - @my_uuid_synthetic;
set @@session.time_zone=@save_tz;
+
+#
+# Bug#42014: Crash, name_const with collate
+#
+CREATE TABLE t1 (a DATE);
+SELECT * FROM t1 WHERE a = NAME_CONST('reportDate',
+ _binary'2009-01-09' COLLATE 'binary');
+DROP TABLE t1;
+
--echo End of 5.0 tests
diff --git a/sql/item.cc b/sql/item.cc
index 182f4abdfe6..49b2010c581 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1243,13 +1243,26 @@ Item::Type Item_name_const::type() const
valid_args guarantees value_item->basic_const_item(); if type is
FUNC_ITEM, then we have a fudged item_func_neg() on our hands
and return the underlying type.
+ For Item_func_set_collation()
+ e.g. NAME_CONST('name', 'value' COLLATE collation) we return its
+ 'value' argument type.
*/
- return valid_args ?
- (((value_item->type() == FUNC_ITEM) &&
- (((Item_func *) value_item)->functype() == Item_func::NEG_FUNC)) ?
- ((Item_func *) value_item)->key_item()->type() :
- value_item->type()) :
- NULL_ITEM;
+ if (!valid_args)
+ return NULL_ITEM;
+ Item::Type value_type= value_item->type();
+ if (value_type == FUNC_ITEM)
+ {
+ /*
+ The second argument of NAME_CONST('name', 'value') must be
+ a simple constant item or a NEG_FUNC/COLLATE_FUNC.
+ */
+ DBUG_ASSERT(((Item_func *) value_item)->functype() ==
+ Item_func::NEG_FUNC ||
+ ((Item_func *) value_item)->functype() ==
+ Item_func::COLLATE_FUNC);
+ return ((Item_func *) value_item)->key_item()->type();
+ }
+ return value_type;
}