Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(parser): stop skipToBlank when meet EOF (#3065)

rebelicee0ee482cc388
diff --git a/plugin/parser/split_multi_sql_test.go b/plugin/parser/split_multi_sql_test.go
index fecaefa5a9..fa84f667ad 100644
--- a/plugin/parser/split_multi_sql_test.go
+++ b/plugin/parser/split_multi_sql_test.go
@@ -237,6 +237,53 @@ func TestPGSplitMultiSQL(t *testing.T) {
func TestMySQLSplitMultiSQL(t *testing.T) {
bigSQL := generateOneMBInsert()
tests := []testData{
+ {
+ statement: "DELIMITER ;;\n" +
+ "CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int\n" +
+ `BEGIN
+
+ DECLARE income INT;
+
+ SET income = 0;
+
+ label1: WHILE income <= 3000 DO
+ SET income = income + starting_value;
+ END WHILE label1;
+
+ RETURN income;
+
+ END ;;
+ DELIMITER ;`,
+ want: resData{
+ res: []SingleSQL{
+ {
+ Text: "DELIMITER ;;",
+ LastLine: 1,
+ },
+ {
+ Text: "CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int\n" +
+ `BEGIN
+
+ DECLARE income INT;
+
+ SET income = 0;
+
+ label1: WHILE income <= 3000 DO
+ SET income = income + starting_value;
+ END WHILE label1;
+
+ RETURN income;
+
+ END ;;`,
+ LastLine: 15,
+ },
+ {
+ Text: "DELIMITER ;",
+ LastLine: 16,
+ },
+ },
+ },
+ },
{
statement: bigSQL,
want: resData{
diff --git a/plugin/parser/tokenizer.go b/plugin/parser/tokenizer.go
index d0aa660428..2037e4b62a 100644
--- a/plugin/parser/tokenizer.go
+++ b/plugin/parser/tokenizer.go
@@ -805,7 +805,7 @@ func (t *tokenizer) skipBlank() {
func (t *tokenizer) skipToBlank() {
r := t.char(0)
- for r != ' ' && r != '\n' && r != '\r' && r != '\t' {
+ for r != ' ' && r != '\n' && r != '\r' && r != '\t' && r != eofRune {
t.skip(1)
r = t.char(0)
}