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

fix -report-type tables bug

  drop table tb
  drop database db
  create database db
上级 b47410a7
......@@ -8,6 +8,18 @@ select * from ta join tb using (id)
[`sakila`.`ta` `sakila`.`tb`]
select * from ta, tb limit 1
[`sakila`.`ta` `sakila`.`tb`]
drop table tb
[`sakila`.tb`]
drop table db.tb
[`db`.`tb`]
drop database db
[`db`.`dual`]
create database db
[`db`.`dual`]
create index idx_col on tbl (col)
[`sakila`.tbl`]
DROP INDEX idx_col on tbl
[`sakila`.tbl`]
SELECT * FROM film WHERE length = 86;
[`sakila`.`film`]
SELECT * FROM film WHERE length IS NULL;
......
......@@ -103,8 +103,32 @@ func SchemaMetaInfo(sql string, defaultDatabase string) []string {
}
}
}
case *ast.DropTableStmt:
// DDL: DROP TABLE|VIEW
schemas := common.JSONFind(jsonString, "Tables")
for _, tabs := range schemas {
for _, table := range gjson.Parse(tabs).Array() {
db := gjson.Get(table.String(), "Schema.O")
tb := gjson.Get(table.String(), "Name.O")
if db.String() == "" {
if tb.String() != "" {
tables = append(tables, fmt.Sprintf("`%s`.%s`", defaultDatabase, tb.String()))
}
} else {
if tb.String() != "" {
tables = append(tables, fmt.Sprintf("`%s`.`%s`", db.String(), tb.String()))
}
}
}
}
case *ast.DropDatabaseStmt, *ast.CreateDatabaseStmt:
// DDL: DROP|CREATE DATABASE
schemas := common.JSONFind(jsonString, "Name")
for _, schema := range schemas {
tables = append(tables, fmt.Sprintf("`%s`.`dual`", schema))
}
default:
// DDL: CREATE TABLE|DATABASE|INDEX|VIEW
// DDL: CREATE TABLE|DATABASE|INDEX|VIEW, DROP INDEX
schemas := common.JSONFind(jsonString, "Table")
for _, table := range schemas {
db := gjson.Get(table, "Schema.O")
......
......@@ -65,7 +65,16 @@ func TestSchemaMetaInfo(t *testing.T) {
"syntax error case",
"select * from ta join tb using (id)",
"select * from ta, tb limit 1",
"drop table tb",
"drop table db.tb",
"drop database db",
"create database db",
"create index idx_col on tbl (col)",
"DROP INDEX idx_col on tbl",
}
// fmt.Println(sqls[len(sqls)-1])
// fmt.Println(SchemaMetaInfo(sqls[len(sqls)-1], "sakila"))
// return
err := common.GoldenDiff(func() {
for _, sql := range append(sqls, common.TestSQLs...) {
fmt.Println(sql)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册