diff --git a/ast/testdata/TestSplitStatement.golden b/ast/testdata/TestSplitStatement.golden index d1d5f4115ce9d12e598815ad5772c10483c3c72f..15e7e66158e03eeacf6140deec60b158792e1958 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 26743448a600d7d4d7030372aeabd72bd5d8715f..05651da60f6c4600c9b4888b72a18af651fda924 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 e59be832650b16e1b5882384e42f9c3e7f312c45..c85f1eaffba4a5f29523e8922433cf7af07cc8f3 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(";"))