Below is the list of changes that have just been committed into a local
5.0 repository of andrey. When andrey 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.1993 05/08/23 16:33:26 andrey@lmy004. +8 -0
fix for bug #12595 (cumulative patch with more test cases)
sql/sql_yacc.yy
1.416 05/08/23 16:33:19 andrey@lmy004. +8 -4
initialize Lex->escape_used in both cases (was found & not found) and then use
Lex->escape_used during
instantiation of Item_func_like object.
sql/sql_lex.h
1.194 05/08/23 16:33:19 andrey@lmy004. +3 -0
declare bool escape_used, used in parsing regarding ESCAPE clause in a SELECT
statement.
sql/sql_lex.cc
1.164 05/08/23 16:33:19 andrey@lmy004. +1 -0
initialize lex->escape_used, used during parsing to pass information between the
stacks whether
ESCAPE was found in the SELECT query.
sql/sql_help.cc
1.50 05/08/23 16:33:19 andrey@lmy004. +2 -1
no ESCAPE in the query - pass the right value for escape_used_in_parsing parameter.
sql/item_cmpfunc.h
1.107 05/08/23 16:33:19 andrey@lmy004. +4 -2
add a boolean which specifies whether ESCAPE was found during parsing - later to be
used in ::fix_fields()
to check whether the size is one code point (though for now Unicode escapes does not
work, but a bug report exists).
pass value for escape_used_in_parsing during instantiation of an object of
Item_func_like.
sql/item_cmpfunc.cc
1.169 05/08/23 16:33:19 andrey@lmy004. +5 -0
check ::numchars() !=1 only when ESCAPE was used in parsing. Otherwise rely on that
our code passes right data (see sql_yacc.yy, "opt_escape" rule).
mysql-test/t/select.test
1.65 05/08/23 16:33:19 andrey@lmy004. +29 -0
test for bug #12595 (ESCAPE should be 1 character)
mysql-test/r/select.result
1.80 05/08/23 16:33:19 andrey@lmy004. +37 -0
test result for bug #12595 (ESCAPE shoule be 1 character)
# 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: andrey
# Host: lmy004.
# Root: /work/mysql-5.0-bug12595-2
--- 1.168/sql/item_cmpfunc.cc 2005-08-18 04:56:11 +02:00
+++ 1.169/sql/item_cmpfunc.cc 2005-08-23 16:33:19 +02:00
@@ -2792,6 +2792,11 @@
{
/* If we are on execution stage */
String *escape_str= escape_item->val_str(&tmp_value1);
+ if (escape_str && escape_used_in_parsing && escape_str->numchars()
!= 1)
+ {
+ my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
+ return TRUE;
+ }
escape= escape_str ? *(escape_str->ptr()) : '\\';
/*
--- 1.106/sql/item_cmpfunc.h 2005-08-13 07:12:56 +02:00
+++ 1.107/sql/item_cmpfunc.h 2005-08-23 16:33:19 +02:00
@@ -961,13 +961,15 @@
enum { alphabet_size = 256 };
Item *escape_item;
+ bool escape_used_in_parsing;
public:
char escape;
- Item_func_like(Item *a,Item *b, Item *escape_arg)
+ Item_func_like(Item *a,Item *b, Item *escape_arg, bool escape_used)
:Item_bool_func2(a,b), canDoTurboBM(FALSE), pattern(0), pattern_len(0),
- bmGs(0), bmBc(0), escape_item(escape_arg) {}
+ bmGs(0), bmBc(0), escape_item(escape_arg),
+ escape_used_in_parsing(escape_used) {}
longlong val_int();
enum Functype functype() const { return LIKE_FUNC; }
optimize_type select_optimize() const;
--- 1.163/sql/sql_lex.cc 2005-08-18 20:46:16 +02:00
+++ 1.164/sql/sql_lex.cc 2005-08-23 16:33:19 +02:00
@@ -173,6 +173,7 @@
lex->spcont= NULL;
lex->proc_list.first= 0;
lex->query_tables_own_last= 0;
+ lex->escape_used= FALSE;
if (lex->sroutines.records)
my_hash_reset(&lex->sroutines);
--- 1.193/sql/sql_lex.h 2005-08-15 17:31:01 +02:00
+++ 1.194/sql/sql_lex.h 2005-08-23 16:33:19 +02:00
@@ -869,6 +869,9 @@
*/
uchar *fname_start, *fname_end;
+ /* Was ESCAPE clause used or not */
+ bool escape_used;
+
st_lex();
virtual ~st_lex()
--- 1.415/sql/sql_yacc.yy 2005-08-18 02:12:34 +02:00
+++ 1.416/sql/sql_yacc.yy 2005-08-23 16:33:19 +02:00
@@ -4263,9 +4263,9 @@
{ $$= new Item_func_eq(new Item_func_soundex($1),
new Item_func_soundex($4)); }
| bit_expr LIKE simple_expr opt_escape
- { $$= new Item_func_like($1,$3,$4); }
+ { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
| bit_expr not LIKE simple_expr opt_escape
- { $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
+ { $$= new Item_func_not(new Item_func_like($1,$4,$5,Lex->escape_used)); }
| bit_expr REGEXP bit_expr { $$= new Item_func_regex($1,$3); }
| bit_expr not REGEXP bit_expr
{ $$= negate_expression(YYTHD, new Item_func_regex($1,$4)); }
@@ -5594,10 +5594,14 @@
;
opt_escape:
- ESCAPE_SYM simple_expr { $$= $2; }
+ ESCAPE_SYM simple_expr
+ {
+ Lex->escape_used= TRUE;
+ $$= $2;
+ }
| /* empty */
{
-
+ Lex->escape_used= FALSE;
$$= ((YYTHD->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) ?
new Item_string("", 0, &my_charset_latin1) :
new Item_string("\\", 1, &my_charset_latin1));
--- 1.79/mysql-test/r/select.result 2005-08-18 04:56:11 +02:00
+++ 1.80/mysql-test/r/select.result 2005-08-23 16:33:19 +02:00
@@ -2756,3 +2756,40 @@
select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0;
x'10' + 0 X'10' + 0 b'10' + 0 B'10' + 0
16 16 2 2
+SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE='';
+show local variables like 'SQL_MODE';
+Variable_name Value
+sql_mode
+CREATE TABLE BUG_12595(a varchar(100));
+INSERT INTO BUG_12595 VALUES ('hakan%'), ('hakank'), ("ha%an");
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan*%' ESCAPE '*';
+a
+hakan%
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '**';
+ERROR HY000: Incorrect arguments to ESCAPE
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '';
+ERROR HY000: Incorrect arguments to ESCAPE
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha%%an' ESCAPE '%';
+a
+ha%an
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE '\\';
+a
+ha%an
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha|%an' ESCAPE '\|';
+a
+ha%an
+SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
+show local variables like 'SQL_MODE';
+Variable_name Value
+sql_mode NO_BACKSLASH_ESCAPES
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%';
+a
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan|%' ESCAPE '|';
+a
+hakan%
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%' ESCAPE '\\';
+ERROR HY000: Incorrect arguments to ESCAPE
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\n%' ESCAPE '\n';
+ERROR HY000: Incorrect arguments to ESCAPE
+SET @@SQL_MODE=@OLD_SQL_MODE;
+DROP TABLE BUG_12595;
--- 1.64/mysql-test/t/select.test 2005-08-18 04:56:11 +02:00
+++ 1.65/mysql-test/t/select.test 2005-08-23 16:33:19 +02:00
@@ -2348,3 +2348,32 @@
#
select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0;
+
+#
+# BUG #12595
+#
+SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE='';
+show local variables like 'SQL_MODE';
+
+CREATE TABLE BUG_12595(a varchar(100));
+INSERT INTO BUG_12595 VALUES ('hakan%'), ('hakank'), ("ha%an");
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan*%' ESCAPE '*';
+-- error 1210
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '**';
+-- error 1210
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '';
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha%%an' ESCAPE '%';
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE '\\';
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha|%an' ESCAPE '\|';
+
+SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
+show local variables like 'SQL_MODE';
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%';
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan|%' ESCAPE '|';
+-- error 1210
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%' ESCAPE '\\';
+-- error 1210
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\n%' ESCAPE '\n';
+
+SET @@SQL_MODE=@OLD_SQL_MODE;
+DROP TABLE BUG_12595;
--- 1.49/sql/sql_help.cc 2005-08-18 02:12:33 +02:00
+++ 1.50/sql/sql_help.cc 2005-08-23 16:33:19 +02:00
@@ -599,7 +599,8 @@
{
Item *cond= new Item_func_like(new Item_field(pfname),
new Item_string(mask,mlen,pfname->charset()),
- new Item_string("\\",1,&my_charset_latin1));
+ new Item_string("\\",1,&my_charset_latin1),
+ FALSE);
if (thd->is_fatal_error)
return 0; // OOM
return prepare_simple_select(thd, cond, table, error);
| Thread |
|---|
| • bk commit into 5.0 tree (andrey:1.1993) BUG#12595 | ahristov | 23 Aug |