Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: sikp empty statement for MySQL (#8094)
rebelice7304d06d05a1
diff --git a/backend/plugin/parser/sql/mysql.go b/backend/plugin/parser/sql/mysql.goindex 8c49b81307..c7ec726840 100644--- a/backend/plugin/parser/sql/mysql.go+++ b/backend/plugin/parser/sql/mysql.go@@ -384,6 +384,10 @@ func parseInputStream(input *antlr.InputStream) ([]*MySQLParseResult, error) {return nil, err}+ if isEmptyStatement(tokens) {+ continue+ }+result = append(result, &MySQLParseResult{Tree: tree,Tokens: tokens,@@ -394,6 +398,15 @@ func parseInputStream(input *antlr.InputStream) ([]*MySQLParseResult, error) {return result, nil}+func isEmptyStatement(tokens *antlr.CommonTokenStream) bool {+ for _, token := range tokens.GetAllTokens() {+ if token.GetChannel() == antlr.TokenDefaultChannel && token.GetTokenType() != parser.MySQLParserSEMICOLON_SYMBOL && token.GetTokenType() != parser.MySQLParserEOF {+ return false+ }+ }+ return true+}+// MySQLValidateForEditor validates the given SQL statement for editor.func MySQLValidateForEditor(tree antlr.Tree) error {l := &mysqlValidateForEditorListener{diff --git a/backend/plugin/parser/sql/mysql_test.go b/backend/plugin/parser/sql/mysql_test.goindex f11b4f38e7..a26d3cc611 100644--- a/backend/plugin/parser/sql/mysql_test.go+++ b/backend/plugin/parser/sql/mysql_test.go@@ -12,6 +12,7 @@ func TestMySQLParser(t *testing.T) {tests := []struct {statement stringerrorMessage string+ total int}{{statement: "aaa",@@ -19,15 +20,19 @@ func TestMySQLParser(t *testing.T) {},{statement: "select * from t;\n -- comments",+ total: 1,},{statement: "SELECT count(t.a) as TID from t1 as t;",+ total: 1,},{- statement: "SELECT * FROM t1 WHERE c1 = 1; SELECT * FROM t2;",+ statement: "SELECT * FROM t1 WHERE c1 = 1; SELECT * FROM t2; ",+ total: 2,},{statement: "CREATE TABLE t1 (c1 INT);",+ total: 1,},{statement: `@@ -60,6 +65,7 @@ func TestMySQLParser(t *testing.T) {CALL complex_procedure('MySQL', @output_value);SELECT @output_value;`,+ total: 4,},{statement: `CREATE TABLE IF NOT EXISTS test_table (@@ -71,13 +77,15 @@ func TestMySQLParser(t *testing.T) {REPLACE INTO test_table (id, name, description)VALUES (1, 'Test', 'This is a test.');`,+ total: 2,},}for i, test := range tests {- _, err := ParseMySQL(test.statement)+ list, err := ParseMySQL(test.statement)if test.errorMessage == "" {require.NoError(t, err, i)+ require.Equal(t, test.total, len(list), i)} else {require.EqualError(t, err, test.errorMessage)}