From 35c5c678646f02bf148a0a9874491bd9fb65d17e Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Tue, 28 May 2019 12:48:31 +0800 Subject: [PATCH] fix issue #208 https://github.com/XiaoMi/soar/issues/208 --- ast/testdata/TestSplitStatement.golden | 1 + ast/token.go | 2 +- ast/token_test.go | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ast/testdata/TestSplitStatement.golden b/ast/testdata/TestSplitStatement.golden index d1d5f41..15e7e66 100644 --- a/ast/testdata/TestSplitStatement.golden +++ b/ast/testdata/TestSplitStatement.golden @@ -39,6 +39,7 @@ tb; 19 INSERT /*+ SET_VAR(foreign_key_checks=OFF) */ INTO t2 VALUES(2); 20 select /*!50000 1,*/ 1; 21 UPDATE xxx SET c1=' LOGGER.error(""); }' WHERE id = 2 ; +22 UPDATE `xxx` SET aaa='a;' WHERE `id` = 15; 0 select * from test\G 1 select 'hello\Gworld', col from test\G 2 -- select * from test\Ghello diff --git a/ast/token.go b/ast/token.go index 2674344..05651da 100644 --- a/ast/token.go +++ b/ast/token.go @@ -933,7 +933,7 @@ func SplitStatement(buf []byte, delimiter []byte) (string, string, []byte) { if i > 1 && buf[i-1] != '\\' { if quoted && b == quoteRune { quoted = false - quoteRune = '0' + quoteRune = 0 } else { // check if first time found quote if quoteRune == 0 { diff --git a/ast/token_test.go b/ast/token_test.go index e59be83..c85f1ea 100644 --- a/ast/token_test.go +++ b/ast/token_test.go @@ -171,6 +171,7 @@ select col from tb; []byte(`INSERT /*+ SET_VAR(foreign_key_checks=OFF) */ INTO t2 VALUES(2);`), // 19 []byte(`select /*!50000 1,*/ 1;`), // 20 []byte(`UPDATE xxx SET c1=' LOGGER.error(""); }' WHERE id = 2 ;`), // 21 + []byte("UPDATE `xxx` SET aaa='a;' WHERE `id` = 15;"), // 22 } // \G 分隔符 buf2s := [][]byte{ @@ -184,6 +185,9 @@ select col from tb; \\G*/ from test\\Ghello`), // 6 } + // single sql test + // SplitStatement(bufs[22], []byte(";")) + // return err := common.GoldenDiff(func() { for i, buf := range bufs { sql, _, _ := SplitStatement(buf, []byte(";")) -- GitLab