diff --git a/ast/testdata/TestQueryType.golden b/ast/testdata/TestQueryType.golden index 8f016975030de5f801610d28d1e7c32e3b06f46b..d54070fa590d4dd234f42a825e8f1bf4b4b32148 100644 --- a/ast/testdata/TestQueryType.golden +++ b/ast/testdata/TestQueryType.golden @@ -1,5 +1,6 @@ SELECT SELECT +SELECT GRANT REVOKE SELECT diff --git a/ast/token.go b/ast/token.go index 70afb522bde040a08a3db897bed70213d08e316b..341633250e5c4be616975ee1d27ab4fefbd4ce3e 100644 --- a/ast/token.go +++ b/ast/token.go @@ -1000,5 +1000,5 @@ func QueryType(sql string) string { } } } - return "" + return "UNKNOWN" } diff --git a/ast/token_test.go b/ast/token_test.go index c8f7ec998ba9792012ad365000433376390d9b2e..ef7f18ef399cd60e420e60cbd3aeb37caf2158bf 100644 --- a/ast/token_test.go +++ b/ast/token_test.go @@ -241,6 +241,7 @@ func TestNewLines(t *testing.T) { func TestQueryType(t *testing.T) { common.Log.Debug("Entering function: %s", common.GetFunctionName()) var testSQLs = []string{ + ` select 1`, `/*comment*/ select 1`, `(select 1)`, `grant select on *.* to user@'localhost'`, diff --git a/cmd/soar/soar.go b/cmd/soar/soar.go index ad4c1173e09b4efe26e3e6327afc6eed9bd07133..87a378dcc87181913c45a004644ebfe752adee2c 100644 --- a/cmd/soar/soar.go +++ b/cmd/soar/soar.go @@ -163,10 +163,6 @@ func main() { _, err = pretty.Println(ast.Tokenize(sql)) common.LogIfWarn(err, "") continue - case "query-type": - // query type by first key word - fmt.Println(ast.QueryType(sql)) - continue default: // SQL 签名 id = query.Id(fingerprint) @@ -190,7 +186,8 @@ func main() { if syntaxErr != nil { errContent := fmt.Sprintf("At SQL %d : %v", sqlCounter, syntaxErr) common.Log.Warning(errContent) - if common.Config.OnlySyntaxCheck || common.Config.ReportType == "rewrite" { + if common.Config.OnlySyntaxCheck || common.Config.ReportType == "rewrite" || + common.Config.ReportType == "query-type" { fmt.Println(errContent) os.Exit(1) } @@ -208,6 +205,11 @@ func main() { env.ChangeDB(vEnv.Connector, q.Query) tables[id] = ast.SchemaMetaInfo(sql, vEnv.Database) continue + case "query-type": + fmt.Println(syntaxErr) + // query type by first key word + fmt.Println(ast.QueryType(sql)) + continue } // +++++++++++++++++++++启发式规则建议[开始]+++++++++++++++++++++++{