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

fix #116

  SplitStatement check if single comment line is in multi-line sql.

  pure comment line should break quickly, single comment in multi-line
  sql should wait for line delimiter
上级 eeeab8ed
......@@ -16,6 +16,21 @@
13 select
*
-- comment
from tb
where col = 1
14 select
* --
from tb
where col = 1
15 select
* #
from tb
where col = 1
16 select
*
--
from tb
where col = 1
0 select * from test\Ghello
1 select 'hello\Gworld', col from test\Ghello
2 -- select * from test\Ghello
......
......@@ -928,7 +928,12 @@ func SplitStatement(buf []byte, delimiter []byte) (string, string, []byte) {
if singleLineComment {
if b == '\r' || b == '\n' {
sql = string(buf[:i])
break
if strings.HasPrefix(sql, "--") || strings.HasPrefix(sql, "#") {
// just comment, query start with '--', '#'
break
}
// comment in multi-line sql
continue
}
}
......
......@@ -131,6 +131,19 @@ func TestSplitStatement(t *testing.T) {
*
-- comment
from tb
where col = 1`),
[]byte(`select
* --
from tb
where col = 1`),
[]byte(`select
* #
from tb
where col = 1`),
[]byte(`select
*
--
from tb
where col = 1`),
}
buf2s := [][]byte{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册