mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
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. (approved patch applied on a up-to-date tree re-commit) mysql-test/r/select.result: results of test for bug 12595 mysql-test/t/select.test: test for bug #12595 (ESCAPE must be exactly one character long) sql/item_cmpfunc.cc: if ESCAPE was in the statement check whether its length is different than 1. In NO_BACKSLASH_ESCAPES mode only length of 1 is allowed, otherwise the length could be 0 or 1 character (code point in the sense of Unicode). sql/item_cmpfunc.h: pass variable from the parsing stage - whether ESCAPE clause was found in the statement sql/sql_help.cc: pass FALSE for escape_used_in_parsing because we want the default mode of no error checking - our internal code. sql/sql_lex.cc: initialized variable used to transfer information during parsing up in the stack when reducing in the grammar sql/sql_lex.h: new variable used for transfering information when reducing in the grammar. sql/sql_yacc.yy: 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.
This commit is contained in:
@ -2965,6 +2965,63 @@ NULL
|
||||
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');
|
||||
|
Reference in New Issue
Block a user