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

-report-type query-type add syntax check

上级 471e0d35
SELECT SELECT
SELECT SELECT
SELECT
GRANT GRANT
REVOKE REVOKE
SELECT SELECT
......
...@@ -1000,5 +1000,5 @@ func QueryType(sql string) string { ...@@ -1000,5 +1000,5 @@ func QueryType(sql string) string {
} }
} }
} }
return "" return "UNKNOWN"
} }
...@@ -241,6 +241,7 @@ func TestNewLines(t *testing.T) { ...@@ -241,6 +241,7 @@ func TestNewLines(t *testing.T) {
func TestQueryType(t *testing.T) { func TestQueryType(t *testing.T) {
common.Log.Debug("Entering function: %s", common.GetFunctionName()) common.Log.Debug("Entering function: %s", common.GetFunctionName())
var testSQLs = []string{ var testSQLs = []string{
` select 1`,
`/*comment*/ select 1`, `/*comment*/ select 1`,
`(select 1)`, `(select 1)`,
`grant select on *.* to user@'localhost'`, `grant select on *.* to user@'localhost'`,
......
...@@ -163,10 +163,6 @@ func main() { ...@@ -163,10 +163,6 @@ func main() {
_, err = pretty.Println(ast.Tokenize(sql)) _, err = pretty.Println(ast.Tokenize(sql))
common.LogIfWarn(err, "") common.LogIfWarn(err, "")
continue continue
case "query-type":
// query type by first key word
fmt.Println(ast.QueryType(sql))
continue
default: default:
// SQL 签名 // SQL 签名
id = query.Id(fingerprint) id = query.Id(fingerprint)
...@@ -190,7 +186,8 @@ func main() { ...@@ -190,7 +186,8 @@ func main() {
if syntaxErr != nil { if syntaxErr != nil {
errContent := fmt.Sprintf("At SQL %d : %v", sqlCounter, syntaxErr) errContent := fmt.Sprintf("At SQL %d : %v", sqlCounter, syntaxErr)
common.Log.Warning(errContent) 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) fmt.Println(errContent)
os.Exit(1) os.Exit(1)
} }
...@@ -208,6 +205,11 @@ func main() { ...@@ -208,6 +205,11 @@ func main() {
env.ChangeDB(vEnv.Connector, q.Query) env.ChangeDB(vEnv.Connector, q.Query)
tables[id] = ast.SchemaMetaInfo(sql, vEnv.Database) tables[id] = ast.SchemaMetaInfo(sql, vEnv.Database)
continue 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.
先完成此消息的编辑!
想要评论请 注册