diff --git a/ast/testdata/TestSplitStatement.golden b/ast/testdata/TestSplitStatement.golden index 2bec02834b18ae47ac315feab378160252af8962..a3e10ae4d3d067a0e18d74abd726ea8f0f3e69fc 100644 --- a/ast/testdata/TestSplitStatement.golden +++ b/ast/testdata/TestSplitStatement.golden @@ -31,7 +31,10 @@ where col = 1 -- from tb where col = 1 -17 +17 select * from +-- comment +tb; +18 -- comment 0 select * from test\Ghello 1 select 'hello\Gworld', col from test\Ghello diff --git a/ast/token.go b/ast/token.go index ac0add0d80e8516d7b433425c4b5e213e0348c8c..ea64ee9a61ac7cd2fd4079e21ed31c4fc4993ce0 100644 --- a/ast/token.go +++ b/ast/token.go @@ -928,6 +928,7 @@ func SplitStatement(buf []byte, delimiter []byte) (string, string, []byte) { if b == '\r' || b == '\n' { if singleLineComment { sql = string(buf[:i]) + singleLineComment = false if strings.HasPrefix(strings.TrimSpace(sql), "--") || strings.HasPrefix(strings.TrimSpace(sql), "#") { // just comment, query start with '--', '#' diff --git a/ast/token_test.go b/ast/token_test.go index 5acce539a17da9e8a0955cea4c5948479a4aa6bb..97d62542362106de893f45674a2dc788d332e164 100644 --- a/ast/token_test.go +++ b/ast/token_test.go @@ -146,6 +146,10 @@ where col = 1`), -- from tb where col = 1`), + []byte(`select * from +-- comment +tb; +select col from tb where col = 1;`), // https://github.com/XiaoMi/soar/issues/120 []byte(` -- comment