Skip to content

Commit

Permalink
refix #116
Browse files Browse the repository at this point in the history
  single line comment in sql will merge next line into before one.
  • Loading branch information
martianzhang committed Nov 23, 2018
1 parent de99de7 commit e08a3b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ast/testdata/TestSplitStatement.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ast/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 '--', '#'
Expand Down
4 changes: 4 additions & 0 deletions ast/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e08a3b0

Please sign in to comment.