From 232dc91bc957bfc3e08d08cec940d5fc8021799e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 3 Nov 2016 22:40:19 +0100 Subject: [PATCH] bugfix: Item_func_like::print() was losing ESCAPE clause --- mysql-test/r/func_like.result | 8 ++++++++ mysql-test/t/func_like.test | 8 ++++++++ sql/item_cmpfunc.cc | 16 ++++++++++++++++ sql/item_cmpfunc.h | 5 +---- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/func_like.result b/mysql-test/r/func_like.result index 9c8e9727d16..0740e89f8df 100644 --- a/mysql-test/r/func_like.result +++ b/mysql-test/r/func_like.result @@ -254,3 +254,11 @@ DROP TABLE t1; # # End of 10.1 tests # +create view v1 as select 'foo!' like 'foo!!', 'foo!' like 'foo!!' escape '!'; +show create view v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select ('foo!' like 'foo!!') AS `'foo!' like 'foo!!'`,('foo!' like 'foo!!' escape '!') AS `'foo!' like 'foo!!' escape '!'` koi8r koi8r_general_ci +select * from v1; +'foo!' like 'foo!!' 'foo!' like 'foo!!' escape '!' +0 1 +drop view v1; diff --git a/mysql-test/t/func_like.test b/mysql-test/t/func_like.test index d1b9b170a3b..ed648fdc70a 100644 --- a/mysql-test/t/func_like.test +++ b/mysql-test/t/func_like.test @@ -185,3 +185,11 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +# +# Item_func_line::print() +# +create view v1 as select 'foo!' like 'foo!!', 'foo!' like 'foo!!' escape '!'; +show create view v1; +select * from v1; +drop view v1; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index e10a4ba573f..f860ca4f06a 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -5076,6 +5076,22 @@ bool Item_bool_func2::count_sargable_conds(void *arg) return 0; } +void Item_func_like::print(String *str, enum_query_type query_type) +{ + str->append('('); + args[0]->print(str, query_type); + str->append(' '); + str->append(func_name()); + str->append(' '); + args[1]->print(str, query_type); + if (escape_used_in_parsing) + { + str->append(STRING_WITH_LEN(" escape ")); + escape_item->print(str, query_type); + } + str->append(')'); +} + longlong Item_func_like::val_int() { diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index b0120dd6c63..c5c34fa9da7 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1868,10 +1868,7 @@ public: escape_used_in_parsing(escape_used), use_sampling(0) {} longlong val_int(); enum Functype functype() const { return LIKE_FUNC; } - void print(String *str, enum_query_type query_type) - { - Item_func::print_op(str, query_type); - } + void print(String *str, enum_query_type query_type); CHARSET_INFO *compare_collation() const { return cmp_collation.collation; } cond_result eq_cmp_result() const