提交 d22add80 编写于 作者: martianzhang's avatar martianzhang

-report-type query-type add syntax check

上级 471e0d35
SELECT
SELECT
SELECT
GRANT
REVOKE
SELECT
......
......@@ -1000,5 +1000,5 @@ func QueryType(sql string) string {
}
}
}
return ""
return "UNKNOWN"
}
......@@ -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'`,
......
......@@ -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
}
// +++++++++++++++++++++启发式规则建议[开始]+++++++++++++++++++++++{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册