List:Internals« Previous MessageNext Message »
From:ahristov Date:September 10 2005 12:53am
Subject:bk commit into 5.0 tree (andrey:1.1963) BUG#12595
View as plain text  
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.1963 05/09/10 00:52:49 andrey@lmy004. +8 -0
  fix for bug #12595 (ESCAPE must be exactly 1 character long)
  ESCAPE has length of 1 if specified and sql_mode is NO_BACKSLASH_ESCAPES
  or has length of 0 or 1 in every other situation.

  sql/sql_yacc.yy
    1.420 05/09/10 00:52:34 andrey@lmy004. +8 -4
    initialize Lex->escape_used and then use it when reducing.
    This is needed as fix for bug #12595 to distinguish between
    situation where ESCAPE was found and when not because internally
    we may pass a string an empty string and there is no other way
    to find out whether this is correct or not in case of 
    NO_BACKSLASH_ESCAPES mode, which allows only length of 1 if
    ESCAPE is part of the SQL statement.

  sql/sql_lex.h
    1.196 05/09/10 00:52:34 andrey@lmy004. +2 -0
    new variable used for transfering information when
    reducing in the grammar.

  sql/sql_lex.cc
    1.168 05/09/10 00:52:34 andrey@lmy004. +1 -0
    initialized variable used to transfer information during
    parsing up in the stack when reducing in the grammar

  sql/sql_help.cc
    1.50 05/09/10 00:52:34 andrey@lmy004. +2 -1
    pass FALSE for escape_used_in_parsing because we
    want the default mode of no error checking - our internal code.

  sql/item_cmpfunc.h
    1.112 05/09/10 00:52:33 andrey@lmy004. +5 -2
    pass variable from the parsing stage - whether
    ESCAPE clause was found in the statement

  sql/item_cmpfunc.cc
    1.176 05/09/10 00:52:33 andrey@lmy004. +10 -0
    if ESCAPE was in the statement check whether its length is
    different that 1. In NO_BACKSLASH_ESCAPES only length of 1 is
    allowed, otherwise the length could be 0 or 1 character (code point
    in the sense of Unicode).

  mysql-test/t/select.test
    1.75 05/09/10 00:52:33 andrey@lmy004. +39 -0
    test for bug #12595 (ESCAPE must be exactly one character long)

  mysql-test/r/select.result
    1.90 05/09/10 00:52:33 andrey@lmy004. +57 -0
    results of test for bug 12595

# 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-3

--- 1.175/sql/item_cmpfunc.cc	2005-09-08 00:56:52 +02:00
+++ 1.176/sql/item_cmpfunc.cc	2005-09-10 00:52:33 +02:00
@@ -2952,8 +2952,18 @@
   {
     /* If we are on execution stage */
     String *escape_str= escape_item->val_str(&tmp_value1);
+
     if (escape_str)
     {
+      if (escape_used_in_parsing && (
+             (((thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
+                escape_str->numchars() != 1) ||
+               escape_str->numchars() > 1)))
+        {
+          my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
+          return TRUE;
+        }
+
       CHARSET_INFO *cs= cmp.cmp_collation.collation;
       if (use_mb(cs))
       {

--- 1.111/sql/item_cmpfunc.h	2005-09-08 00:56:52 +02:00
+++ 1.112/sql/item_cmpfunc.h	2005-09-10 00:52:33 +02:00
@@ -985,13 +985,16 @@
   enum { alphabet_size = 256 };
 
   Item *escape_item;
+  
+  bool escape_used_in_parsing;
 
 public:
   int 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.167/sql/sql_lex.cc	2005-09-03 01:13:10 +02:00
+++ 1.168/sql/sql_lex.cc	2005-09-10 00:52:34 +02:00
@@ -175,6 +175,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.195/sql/sql_lex.h	2005-09-03 01:13:10 +02:00
+++ 1.196/sql/sql_lex.h	2005-09-10 00:52:34 +02:00
@@ -877,6 +877,8 @@
     during replication ("LOCAL 'filename' REPLACE INTO" part).
   */
   uchar *fname_start, *fname_end;
+  
+  bool escape_used;
 
   st_lex();
 

--- 1.419/sql/sql_yacc.yy	2005-09-07 21:44:12 +02:00
+++ 1.420/sql/sql_yacc.yy	2005-09-10 00:52:34 +02:00
@@ -4300,9 +4300,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)); }
@@ -5635,10 +5635,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.89/mysql-test/r/select.result	2005-09-08 10:29:49 +02:00
+++ 1.90/mysql-test/r/select.result	2005-09-10 00:52:33 +02:00
@@ -2885,6 +2885,63 @@
 SELECT IFNULL(NULL, NULL);
 IFNULL(NULL, NULL)
 NULL
+SET @OLD_SQL_MODE12595=@@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\%';
+a
+hakan%
+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 '';
+a
+hakan%
+hakank
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%' ESCAPE '';
+a
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE 0x5c;
+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
+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\%' 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 0x5c;
+a
+ha%an
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha|%an' ESCAPE '|';
+a
+ha%an
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\n%' ESCAPE '\n';
+ERROR HY000: Incorrect arguments to ESCAPE
+SET @@SQL_MODE=@OLD_SQL_MODE12595;
+DROP TABLE BUG_12595;
 create table t1 (a char(1));
 create table t2 (a char(1));
 insert into t1 values ('a'),('b'),('c');

--- 1.74/mysql-test/t/select.test	2005-09-08 10:29:49 +02:00
+++ 1.75/mysql-test/t/select.test	2005-09-10 00:52:33 +02:00
@@ -2455,6 +2455,45 @@
 SELECT IFNULL(NULL, NULL);
 
 #
+# BUG #12595 (ESCAPE must be exactly one)
+#
+SET @OLD_SQL_MODE12595=@@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\%';
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan*%' ESCAPE '*';
+-- error 1210
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '**';
+# this should work when sql_mode is not NO_BACKSLASH_ESCAPES
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan%' ESCAPE '';
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%' ESCAPE '';
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE 0x5c;
+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\%' ESCAPE '\\';
+#this gives an error when NO_BACKSLASH_ESCAPES is set
+-- error 1210
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan%' ESCAPE '';
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE 0x5c;
+SELECT * FROM BUG_12595 WHERE a LIKE 'ha|%an' ESCAPE '|';
+-- error 1210
+SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\n%' ESCAPE '\n';
+
+SET @@SQL_MODE=@OLD_SQL_MODE12595;
+DROP TABLE BUG_12595;
+
+#
 # Bug #6495 Illogical requirement for column qualification in NATURAL join
 #
 

--- 1.49/sql/sql_help.cc	2005-08-18 02:12:33 +02:00
+++ 1.50/sql/sql_help.cc	2005-09-10 00:52:34 +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.1963) BUG#12595ahristov10 Sep