From e08a3b056a37ccabb9cb51a075df864fedbef469 Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Fri, 23 Nov 2018 14:40:14 +0800 Subject: [PATCH] refix #116 single line comment in sql will merge next line into before one. --- ast/testdata/TestSplitStatement.golden | 5 ++++- ast/token.go | 1 + ast/token_test.go | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ast/testdata/TestSplitStatement.golden b/ast/testdata/TestSplitStatement.golden index 2bec028..a3e10ae 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 ac0add0..ea64ee9 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 5acce53..97d6254 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 -- GitLab