Skip to content

Commit 8673c64

Browse files
author
auxten
committed
Fix test case for SQLite unsupported escape with '\'
1 parent 0e8b2d5 commit 8673c64

5 files changed

Lines changed: 22 additions & 47 deletions

File tree

comments_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -347,29 +347,3 @@ func TestExtractCommentDirectives(t *testing.T) {
347347
}
348348
}
349349

350-
func TestSkipQueryPlanCacheDirective(t *testing.T) {
351-
stmt, _ := Parse("insert /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ into user(id) values (1), (2)")
352-
if !SkipQueryPlanCacheDirective(stmt) {
353-
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true")
354-
}
355-
356-
stmt, _ = Parse("insert into user(id) values (1), (2)")
357-
if SkipQueryPlanCacheDirective(stmt) {
358-
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be false")
359-
}
360-
361-
stmt, _ = Parse("update /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ users set name=1")
362-
if !SkipQueryPlanCacheDirective(stmt) {
363-
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true")
364-
}
365-
366-
stmt, _ = Parse("select /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ * from users")
367-
if !SkipQueryPlanCacheDirective(stmt) {
368-
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true")
369-
}
370-
371-
stmt, _ = Parse("delete /*vt+ SKIP_QUERY_PLAN_CACHE=1 */ from users")
372-
if !SkipQueryPlanCacheDirective(stmt) {
373-
t.Errorf("d.SkipQueryPlanCacheDirective(stmt) should be true")
374-
}
375-
}

dependency/sqltypes/value.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ func encodeBytesSQL(val []byte, b BinWriter) {
324324
if encodedChar := SQLEncodeMap[ch]; encodedChar == DontEscape {
325325
buf.WriteByte(ch)
326326
} else {
327-
buf.WriteByte('\\')
327+
if ch == '\'' {
328+
buf.WriteByte('\'')
329+
} else {
330+
buf.WriteByte('\\')
331+
}
328332
buf.WriteByte(encodedChar)
329333
}
330334
}
@@ -358,7 +362,6 @@ var encodeRef = map[byte]byte{
358362
'\r': 'r',
359363
'\t': 't',
360364
26: 'Z', // ctl-Z
361-
'\\': '\\',
362365
}
363366

364367
func init() {

dependency/sqltypes/value_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ func TestEncode(t *testing.T) {
379379
outSQL: "'foo'",
380380
outASCII: "'Zm9v'",
381381
}, {
382-
in: TestValue(VarChar, "\x00'\"\b\n\r\t\x1A\\"),
383-
outSQL: "'\\0\\'\\\"\\b\\n\\r\\t\\Z\\\\'",
382+
in: TestValue(VarChar, "\x00''\b\n\r\t\x1A\\"),
383+
outSQL: `\x00''\b\n\r\t\x1A\\`,
384384
outASCII: "'ACciCAoNCRpc'",
385385
}}
386386
for _, tcase := range testcases {

parse_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ var (
2929
output string
3030
}{{
3131
input: "select 1",
32+
}, {
33+
input: "insert /* simple */ into a values (1)",
3234
}, {
3335
input: "select 1 from t",
3436
}, {
@@ -383,22 +385,20 @@ var (
383385
output: "select /* double quoted string */ 'a' from t",
384386
}, {
385387
input: "select /* quote quote in string */ 'a''a' from t",
386-
output: "select /* quote quote in string */ 'a\\'a' from t",
388+
output: "select /* quote quote in string */ 'a''a' from t",
387389
}, {
388390
input: "select /* double quote quote in string */ \"a\"\"a\" from t",
389391
output: "select /* double quote quote in string */ 'a\\\"a' from t",
390392
}, {
391393
input: "select /* quote in double quoted string */ \"a'a\" from t",
392-
output: "select /* quote in double quoted string */ 'a\\'a' from t",
394+
output: "select /* quote in double quoted string */ 'a''a' from t",
393395
}, {
394-
input: "select /* backslash quote in string */ 'a\\'a' from t",
396+
input: "select /* backslash quote in string */ 'a''a' from t",
397+
output: "select /* backslash quote in string */ 'a''a' from t",
395398
}, {
396399
input: "select /* literal backslash in string */ 'a\\\\na' from t",
397-
}, {
398-
input: "select /* all escapes */ '\\0\\'\\\"\\b\\n\\r\\t\\Z\\\\' from t",
399400
}, {
400401
input: "select /* non-escape */ '\\x' from t",
401-
output: "select /* non-escape */ 'x' from t",
402402
}, {
403403
input: "select /* unescaped backslash */ '\\n' from t",
404404
}, {
@@ -494,8 +494,6 @@ var (
494494
output: "select 1 from t",
495495
}, {
496496
input: "select /* dual */ 1 from dual",
497-
}, {
498-
input: "insert /* simple */ into a values (1)",
499497
}, {
500498
input: "insert /* a.b */ into a.b values (1)",
501499
}, {
@@ -1208,7 +1206,7 @@ var (
12081206
excludeMulti: true,
12091207
}, {
12101208
input: "select 'aa\\",
1211-
output: "syntax error at position 12 near 'aa'",
1209+
output: "syntax error at position 12 near 'aa\\'",
12121210
excludeMulti: true,
12131211
}, {
12141212
input: "select /* aa",

token_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,39 @@ func TestString(t *testing.T) {
9494
}, {
9595
in: "'\\n'",
9696
id: STRING,
97-
want: "\n",
97+
want: "\\n",
9898
}, {
9999
in: "'\\nhello\\n'",
100100
id: STRING,
101-
want: "\nhello\n",
101+
want: "\\nhello\\n",
102102
}, {
103103
in: "'a''b'",
104104
id: STRING,
105105
want: "a'b",
106106
}, {
107107
in: "'a\\'b'",
108108
id: STRING,
109-
want: "a'b",
109+
want: "a\\",
110110
}, {
111111
in: "'\\'",
112-
id: LEX_ERROR,
113-
want: "'",
112+
id: STRING,
113+
want: "\\",
114114
}, {
115115
in: "'",
116116
id: LEX_ERROR,
117117
want: "",
118118
}, {
119119
in: "'hello\\'",
120-
id: LEX_ERROR,
121-
want: "hello'",
120+
id: STRING,
121+
want: "hello\\",
122122
}, {
123123
in: "'hello",
124124
id: LEX_ERROR,
125125
want: "hello",
126126
}, {
127127
in: "'hello\\",
128128
id: LEX_ERROR,
129-
want: "hello",
129+
want: "hello\\",
130130
}}
131131

132132
for _, tcase := range testcases {

0 commit comments

Comments
 (0)