提交 d23dfdb4 编写于 作者: martianzhang's avatar martianzhang

fix #120

  trimspace before check single line comment
上级 a4a641a6
...@@ -31,6 +31,8 @@ where col = 1 ...@@ -31,6 +31,8 @@ where col = 1
-- --
from tb from tb
where col = 1 where col = 1
17
-- comment
0 select * from test\Ghello 0 select * from test\Ghello
1 select 'hello\Gworld', col from test\Ghello 1 select 'hello\Gworld', col from test\Ghello
2 -- select * from test\Ghello 2 -- select * from test\Ghello
......
...@@ -925,16 +925,18 @@ func SplitStatement(buf []byte, delimiter []byte) (string, string, []byte) { ...@@ -925,16 +925,18 @@ func SplitStatement(buf []byte, delimiter []byte) (string, string, []byte) {
} }
// new line end single line comment // new line end single line comment
if singleLineComment { if b == '\r' || b == '\n' {
if b == '\r' || b == '\n' { if singleLineComment {
sql = string(buf[:i]) sql = string(buf[:i])
if strings.HasPrefix(sql, "--") || strings.HasPrefix(sql, "#") { if strings.HasPrefix(strings.TrimSpace(sql), "--") ||
strings.HasPrefix(strings.TrimSpace(sql), "#") {
// just comment, query start with '--', '#' // just comment, query start with '--', '#'
break break
} }
// comment in multi-line sql // comment in multi-line sql
continue continue
} }
continue
} }
// multi line comment // multi line comment
......
...@@ -127,6 +127,7 @@ func TestSplitStatement(t *testing.T) { ...@@ -127,6 +127,7 @@ func TestSplitStatement(t *testing.T) {
[]byte(`--`), []byte(`--`),
[]byte(`-- comment`), []byte(`-- comment`),
[]byte(`# comment`), []byte(`# comment`),
// https://github.com/XiaoMi/soar/issues/116
[]byte(`select []byte(`select
* *
-- comment -- comment
...@@ -145,6 +146,12 @@ where col = 1`), ...@@ -145,6 +146,12 @@ where col = 1`),
-- --
from tb from tb
where col = 1`), where col = 1`),
// https://github.com/XiaoMi/soar/issues/120
[]byte(`
-- comment
select col from tb;
select col from tb;
`),
} }
buf2s := [][]byte{ buf2s := [][]byte{
[]byte("select * from test\\Ghello"), []byte("select * from test\\Ghello"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册