提交 a2b44da7 编写于 作者: L liuzhenwu

fix sql comment distinguish in quoted string

上级 ee6cfd0c
...@@ -40,6 +40,7 @@ tb; ...@@ -40,6 +40,7 @@ tb;
20 select /*!50000 1,*/ 1; 20 select /*!50000 1,*/ 1;
21 UPDATE xxx SET c1=' LOGGER.error(""); }' WHERE id = 2 ; 21 UPDATE xxx SET c1=' LOGGER.error(""); }' WHERE id = 2 ;
22 UPDATE `xxx` SET aaa='a;' WHERE `id` = 15; 22 UPDATE `xxx` SET aaa='a;' WHERE `id` = 15;
23 UPDATE `xxx` SET aaa='a -- b' WHERE `id` = 15;
0 select * from test\G 0 select * from test\G
1 select 'hello\Gworld', col from test\G 1 select 'hello\Gworld', col from test\G
2 -- select * from test\Ghello 2 -- select * from test\Ghello
......
...@@ -863,12 +863,12 @@ func SplitStatement(buf []byte, delimiter []byte) (string, string, []byte) { ...@@ -863,12 +863,12 @@ func SplitStatement(buf []byte, delimiter []byte) (string, string, []byte) {
b := buf[i] b := buf[i]
// single line comment // single line comment
if b == '-' { if b == '-' {
if i+2 < len(buf) && buf[i+1] == '-' && buf[i+2] == ' ' { if !quoted && i+2 < len(buf) && buf[i+1] == '-' && buf[i+2] == ' ' {
singleLineComment = true singleLineComment = true
i = i + 2 i = i + 2
continue continue
} }
if i+2 < len(buf) && i == 0 && buf[i+1] == '-' && (buf[i+2] == '\n' || buf[i+2] == '\r') { if !quoted && i+2 < len(buf) && i == 0 && buf[i+1] == '-' && (buf[i+2] == '\n' || buf[i+2] == '\r') {
sql = "--\n" sql = "--\n"
break break
} }
......
...@@ -173,7 +173,8 @@ select col from tb; ...@@ -173,7 +173,8 @@ select col from tb;
[]byte(`select /*!50000 1,*/ 1;`), // 20 []byte(`select /*!50000 1,*/ 1;`), // 20
[]byte(`UPDATE xxx SET c1=' LOGGER.error(""); }' WHERE id = 2 ;`), // 21 []byte(`UPDATE xxx SET c1=' LOGGER.error(""); }' WHERE id = 2 ;`), // 21
[]byte("UPDATE `xxx` SET aaa='a;' WHERE `id` = 15;"), // 22 []byte("UPDATE `xxx` SET aaa='a;' WHERE `id` = 15;"), // 22
// []byte(`/* comment here */ SET MAX_JOIN_SIZE=#`), // 23 []byte("UPDATE `xxx` SET aaa='a -- b' WHERE `id` = 15; UPDATE `xxx` SET aaa='c -- d' WHERE `id` = 16;"), // 23
// []byte(`/* comment here */ SET MAX_JOIN_SIZE=#`), // 24
} }
// \G 分隔符 // \G 分隔符
buf2s := [][]byte{ buf2s := [][]byte{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册