Skip to content

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

fix(parser): consider the case that only contains comments (#2564)

rebelice1877ccb40d09
diff --git a/plugin/advisor/mysql/advisor_charset_allowlist_test.go b/plugin/advisor/mysql/advisor_charset_allowlist_test.go
index 47b69b3c7a..0741b3aec9 100644
--- a/plugin/advisor/mysql/advisor_charset_allowlist_test.go
+++ b/plugin/advisor/mysql/advisor_charset_allowlist_test.go
@@ -131,6 +131,17 @@ func TestCharsetAllowlist(t *testing.T) {
},
},
},
+ {
+ Statement: "/* this is a comment */",
+ Want: []advisor.Advice{
+ {
+ Status: advisor.Success,
+ Code: advisor.Ok,
+ Title: "OK",
+ Content: "",
+ },
+ },
+ },
}
payload, err := json.Marshal(advisor.CharsetAllowlistRulePayload{
diff --git a/plugin/advisor/mysql/parser.go b/plugin/advisor/mysql/parser.go
index c845fa486e..6998b300d3 100644
--- a/plugin/advisor/mysql/parser.go
+++ b/plugin/advisor/mysql/parser.go
@@ -35,6 +35,13 @@ func parseStatement(statement string, charset string, collation string) ([]ast.S
},
}
}
+
+ // sikp the setting line stage
+ if len(root) == 0 {
+ return root, nil
+ }
+
+ // setting line stage
sqlList, err := parser.SplitMultiSQL(parser.MySQL, statement)
if err != nil {
return nil, []advisor.Advice{
diff --git a/plugin/advisor/pg/advisor_column_no_null_test.go b/plugin/advisor/pg/advisor_column_no_null_test.go
index ea77f01d74..f6b45d8f5d 100644
--- a/plugin/advisor/pg/advisor_column_no_null_test.go
+++ b/plugin/advisor/pg/advisor_column_no_null_test.go
@@ -124,6 +124,17 @@ func TestColumnNoNULL(t *testing.T) {
},
},
},
+ {
+ Statement: "/* this is a comment */",
+ Want: []advisor.Advice{
+ {
+ Status: advisor.Success,
+ Code: advisor.Ok,
+ Title: "OK",
+ Content: "",
+ },
+ },
+ },
}
advisor.RunSQLReviewRuleTests(t, tests, &ColumnNoNullAdvisor{}, &advisor.SQLReviewRule{
diff --git a/plugin/parser/engine/pg/parser.go b/plugin/parser/engine/pg/parser.go
index 99f456948d..7235bbe58f 100644
--- a/plugin/parser/engine/pg/parser.go
+++ b/plugin/parser/engine/pg/parser.go
@@ -35,6 +35,12 @@ func (*PostgreSQLParser) Parse(_ parser.ParseContext, statement string) ([]ast.N
return nil, err
}
+ // sikp the setting line stage
+ if len(res.Stmts) == 0 {
+ return nil, nil
+ }
+
+ // setting line stage
textList, err := parser.SplitMultiSQL(parser.Postgres, statement)
if err != nil {
return nil, err