Skip to content

Commit e9e5b35

Browse files
author
vva@eagle.mysql.r18.ru
committed
patch for task WL 1941 "NO_C_ESCAPE sql_mode"
1 parent 731c2ac commit e9e5b35

File tree

6 files changed

+353
-3
lines changed

6 files changed

+353
-3
lines changed

mysql-test/r/sql_mode.result

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,252 @@ t1 CREATE TABLE "t1" (
8585
UNIQUE KEY "email" ("email")
8686
)
8787
drop table t1;
88+
SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE='';
89+
show local variables like 'SQL_MODE';
90+
Variable_name Value
91+
sql_mode
92+
CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p));
93+
INSERT t1 (a) VALUES
94+
('\\'),
95+
('\n'),
96+
('\b'),
97+
('\r'),
98+
('\t'),
99+
('\x'),
100+
('\a'),
101+
('\aa'),
102+
('\\a'),
103+
('\\aa'),
104+
('_'),
105+
('\_'),
106+
('\\_'),
107+
('\\\_'),
108+
('\\\\_'),
109+
('%'),
110+
('\%'),
111+
('\\%'),
112+
('\\\%'),
113+
('\\\\%')
114+
;
115+
SELECT p, hex(a) FROM t1;
116+
p hex(a)
117+
1 5C
118+
2 0A
119+
3 08
120+
4 0D
121+
5 09
122+
6 78
123+
7 61
124+
8 6161
125+
9 5C61
126+
10 5C6161
127+
11 5F
128+
12 5C5F
129+
13 5C5F
130+
14 5C5C5F
131+
15 5C5C5F
132+
16 25
133+
17 5C25
134+
18 5C25
135+
19 5C5C25
136+
20 5C5C25
137+
delete from t1 where a in ('\n','\r','\t', '\b');
138+
select
139+
masks.p,
140+
masks.a as mask,
141+
examples.a as example
142+
from
143+
t1 as masks
144+
left join t1 as examples on examples.a LIKE masks.a
145+
order by masks.p, example;
146+
p mask example
147+
1 \ \
148+
6 x x
149+
7 a a
150+
8 aa aa
151+
9 \a a
152+
10 \aa aa
153+
11 _ %
154+
11 _ a
155+
11 _ x
156+
11 _ \
157+
11 _ _
158+
12 \_ _
159+
13 \_ _
160+
14 \\_ \%
161+
14 \\_ \%
162+
14 \\_ \a
163+
14 \\_ \_
164+
14 \\_ \_
165+
15 \\_ \%
166+
15 \\_ \%
167+
15 \\_ \a
168+
15 \\_ \_
169+
15 \\_ \_
170+
16 % %
171+
16 % a
172+
16 % aa
173+
16 % x
174+
16 % \
175+
16 % \%
176+
16 % \%
177+
16 % \a
178+
16 % \aa
179+
16 % \\%
180+
16 % \\%
181+
16 % \\_
182+
16 % \\_
183+
16 % \_
184+
16 % \_
185+
16 % _
186+
17 \% %
187+
18 \% %
188+
19 \\% \
189+
19 \\% \%
190+
19 \\% \%
191+
19 \\% \a
192+
19 \\% \aa
193+
19 \\% \\%
194+
19 \\% \\%
195+
19 \\% \\_
196+
19 \\% \\_
197+
19 \\% \_
198+
19 \\% \_
199+
20 \\% \
200+
20 \\% \%
201+
20 \\% \%
202+
20 \\% \a
203+
20 \\% \aa
204+
20 \\% \\%
205+
20 \\% \\%
206+
20 \\% \\_
207+
20 \\% \\_
208+
20 \\% \_
209+
20 \\% \_
210+
DROP TABLE t1;
211+
SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
212+
show local variables like 'SQL_MODE';
213+
Variable_name Value
214+
sql_mode NO_BACKSLASH_ESCAPES
215+
CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p));
216+
INSERT t1 (a) VALUES
217+
('\\'),
218+
('\n'),
219+
('\b'),
220+
('\r'),
221+
('\t'),
222+
('\x'),
223+
('\a'),
224+
('\aa'),
225+
('\\a'),
226+
('\\aa'),
227+
('_'),
228+
('\_'),
229+
('\\_'),
230+
('\\\_'),
231+
('\\\\_'),
232+
('%'),
233+
('\%'),
234+
('\\%'),
235+
('\\\%'),
236+
('\\\\%')
237+
;
238+
SELECT p, hex(a) FROM t1;
239+
p hex(a)
240+
1 5C5C
241+
2 5C6E
242+
3 5C62
243+
4 5C72
244+
5 5C74
245+
6 5C78
246+
7 5C61
247+
8 5C6161
248+
9 5C5C61
249+
10 5C5C6161
250+
11 5F
251+
12 5C5F
252+
13 5C5C5F
253+
14 5C5C5C5F
254+
15 5C5C5C5C5F
255+
16 25
256+
17 5C25
257+
18 5C5C25
258+
19 5C5C5C25
259+
20 5C5C5C5C25
260+
delete from t1 where a in ('\n','\r','\t', '\b');
261+
select
262+
masks.p,
263+
masks.a as mask,
264+
examples.a as example
265+
from
266+
t1 as masks
267+
left join t1 as examples on examples.a LIKE masks.a
268+
order by masks.p, example;
269+
p mask example
270+
1 \\ \\
271+
6 \x \x
272+
7 \a \a
273+
8 \aa \aa
274+
9 \\a \\a
275+
10 \\aa \\aa
276+
11 _ %
277+
11 _ _
278+
12 \_ \%
279+
12 \_ \a
280+
12 \_ \x
281+
12 \_ \\
282+
12 \_ \_
283+
13 \\_ \\%
284+
13 \\_ \\a
285+
13 \\_ \\_
286+
14 \\\_ \\\%
287+
14 \\\_ \\\_
288+
15 \\\\_ \\\\%
289+
15 \\\\_ \\\\_
290+
16 % %
291+
16 % \%
292+
16 % \a
293+
16 % \aa
294+
16 % \x
295+
16 % \\
296+
16 % \\%
297+
16 % \\a
298+
16 % \\aa
299+
16 % \\\%
300+
16 % \\\\%
301+
16 % \\\\_
302+
16 % \\\_
303+
16 % \\_
304+
16 % \_
305+
16 % _
306+
17 \% \%
307+
17 \% \a
308+
17 \% \aa
309+
17 \% \x
310+
17 \% \\
311+
17 \% \\%
312+
17 \% \\a
313+
17 \% \\aa
314+
17 \% \\\%
315+
17 \% \\\\%
316+
17 \% \\\\_
317+
17 \% \\\_
318+
17 \% \\_
319+
17 \% \_
320+
18 \\% \\
321+
18 \\% \\%
322+
18 \\% \\a
323+
18 \\% \\aa
324+
18 \\% \\\%
325+
18 \\% \\\\%
326+
18 \\% \\\\_
327+
18 \\% \\\_
328+
18 \\% \\_
329+
19 \\\% \\\%
330+
19 \\\% \\\\%
331+
19 \\\% \\\\_
332+
19 \\\% \\\_
333+
20 \\\\% \\\\%
334+
20 \\\\% \\\\_
335+
DROP TABLE t1;
336+
SET @@SQL_MODE=@OLD_SQL_MODE;

mysql-test/t/sql_mode.test

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,98 @@ set sql_mode="postgresql,oracle,mssql,db2,maxdb";
2828
select @@sql_mode;
2929
show create table t1;
3030
drop table t1;
31+
32+
#
33+
# test for
34+
# WL 1941 "NO_C_ESCAPES sql_mode"
35+
#
36+
# an sql_mode to disable \n, \r, \b, etc escapes in string literals. actually, to
37+
# disable special meaning of backslash completely. It's not in the SQL standard
38+
# and it causes some R/3 tests to fail.
39+
#
40+
41+
SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE='';
42+
show local variables like 'SQL_MODE';
43+
44+
CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p));
45+
INSERT t1 (a) VALUES
46+
('\\'),
47+
('\n'),
48+
('\b'),
49+
('\r'),
50+
('\t'),
51+
('\x'),
52+
('\a'),
53+
('\aa'),
54+
('\\a'),
55+
('\\aa'),
56+
('_'),
57+
('\_'),
58+
('\\_'),
59+
('\\\_'),
60+
('\\\\_'),
61+
('%'),
62+
('\%'),
63+
('\\%'),
64+
('\\\%'),
65+
('\\\\%')
66+
;
67+
68+
SELECT p, hex(a) FROM t1;
69+
70+
delete from t1 where a in ('\n','\r','\t', '\b');
71+
72+
select
73+
masks.p,
74+
masks.a as mask,
75+
examples.a as example
76+
from
77+
t1 as masks
78+
left join t1 as examples on examples.a LIKE masks.a
79+
order by masks.p, example;
80+
81+
DROP TABLE t1;
82+
83+
SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
84+
show local variables like 'SQL_MODE';
85+
86+
CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p));
87+
INSERT t1 (a) VALUES
88+
('\\'),
89+
('\n'),
90+
('\b'),
91+
('\r'),
92+
('\t'),
93+
('\x'),
94+
('\a'),
95+
('\aa'),
96+
('\\a'),
97+
('\\aa'),
98+
('_'),
99+
('\_'),
100+
('\\_'),
101+
('\\\_'),
102+
('\\\\_'),
103+
('%'),
104+
('\%'),
105+
('\\%'),
106+
('\\\%'),
107+
('\\\\%')
108+
;
109+
110+
SELECT p, hex(a) FROM t1;
111+
112+
delete from t1 where a in ('\n','\r','\t', '\b');
113+
114+
select
115+
masks.p,
116+
masks.a as mask,
117+
examples.a as example
118+
from
119+
t1 as masks
120+
left join t1 as examples on examples.a LIKE masks.a
121+
order by masks.p, example;
122+
123+
DROP TABLE t1;
124+
125+
SET @@SQL_MODE=@OLD_SQL_MODE;

sql/mysql_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset;
272272
#define MODE_MYSQL40 (MODE_MYSQL323*2)
273273
#define MODE_ANSI (MODE_MYSQL40*2)
274274
#define MODE_NO_AUTO_VALUE_ON_ZERO (MODE_ANSI*2)
275+
#define MODE_NO_BACKSLASH_ESCAPES (MODE_NO_AUTO_VALUE_ON_ZERO*2)
275276

276277
#define RAID_BLOCK_SIZE 1024
277278

sql/mysqld.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ const char *sql_mode_names[] =
223223
"NO_DIR_IN_CREATE",
224224
"POSTGRESQL", "ORACLE", "MSSQL", "DB2", "MAXDB", "NO_KEY_OPTIONS",
225225
"NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS", "MYSQL323", "MYSQL40", "ANSI",
226-
"NO_AUTO_VALUE_ON_ZERO", NullS
226+
"NO_AUTO_VALUE_ON_ZERO", "NO_BACKSLASH_ESCAPES", NullS
227227
};
228228
TYPELIB sql_mode_typelib= { array_elements(sql_mode_names)-1,"",
229229
sql_mode_names };

sql/sql_lex.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ static char *get_text(LEX *lex)
250250
continue;
251251
}
252252
#endif
253-
if (c == '\\')
253+
if (c == '\\' &&
254+
!(lex->thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES))
254255
{ // Escaped character
255256
found_escape=1;
256257
if (lex->ptr == lex->end_of_query)

sql/sql_yacc.yy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4725,7 +4725,11 @@ having_clause:
47254725

47264726
opt_escape:
47274727
ESCAPE_SYM TEXT_STRING_literal { $$= $2.str; }
4728-
| /* empty */ { $$= (char*) "\\"; };
4728+
| /* empty */
4729+
{
4730+
$$= (char*) ((YYTHD->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)
4731+
? "" : "\\");
4732+
};
47294733

47304734

47314735
/*

0 commit comments

Comments
 (0)