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

🐛 fix commna separate join tables info

  select * from t1, t2 limit 1
上级 ac82e632
......@@ -6,6 +6,8 @@ syntax error case
[]
select * from ta join tb using (id)
[`sakila`.`ta` `sakila`.`tb`]
select * from ta, tb limit 1
[`sakila`.`ta` `sakila`.`tb`]
SELECT * FROM film WHERE length = 86;
[`sakila`.`film`]
SELECT * FROM film WHERE length IS NULL;
......@@ -117,9 +119,9 @@ DELETE FROM film WHERE length > 100;
UPDATE city INNER JOIN country USING(country_id) SET city.city = 'Abha', city.last_update = '2006-02-15 04:45:25', country.country = 'Afghanistan' WHERE city.city_id=10;
[`sakila`.`city` `sakila`.`country`]
UPDATE city INNER JOIN country ON city.country_id = country.country_id INNER JOIN address ON city.city_id = address.city_id SET city.city = 'Abha', city.last_update = '2006-02-15 04:45:25', country.country = 'Afghanistan' WHERE city.city_id=10;
[`sakila`.`address`]
[`sakila`.`address` `sakila`.`city` `sakila`.`country`]
UPDATE city, country SET city.city = 'Abha', city.last_update = '2006-02-15 04:45:25', country.country = 'Afghanistan' WHERE city.country_id = country.country_id AND city.city_id=10;
[`sakila`.`country`]
[`sakila`.`city` `sakila`.`country`]
UPDATE film SET length = 10 WHERE language_id = 20;
[`sakila`.`film`]
INSERT INTO city (country_id) SELECT country_id FROM country;
......
......@@ -86,32 +86,20 @@ func SchemaMetaInfo(sql string, defaultDatabase string) []string {
tables = append(tables, fmt.Sprintf("`%s`.`dual`", n.DBName))
case *ast.InsertStmt, *ast.SelectStmt, *ast.UnionStmt, *ast.UpdateStmt, *ast.DeleteStmt:
// DML/DQL: INSERT, SELECT, UPDATE, DELETE
tableRefs := common.JSONFind(jsonString, "TableRefs")
for _, table := range tableRefs {
leftDatabase := gjson.Get(table, "Left.Source.Schema.O")
leftTable := gjson.Get(table, "Left.Source.Name.O")
if leftDatabase.String() == "" {
if leftTable.String() != "" {
tables = append(tables, fmt.Sprintf("`%s`.`%s`", defaultDatabase, leftTable))
}
} else {
if leftTable.String() != "" {
tables = append(tables, fmt.Sprintf("`%s`.`%s`", leftDatabase, leftTable))
} else {
tables = append(tables, fmt.Sprintf("`%s`.`dual`", leftDatabase))
}
}
rightDatabase := gjson.Get(table, "Right.Source.Schema.O")
rightTable := gjson.Get(table, "Right.Source.Name.O")
if rightDatabase.String() == "" {
if rightTable.String() != "" {
tables = append(tables, fmt.Sprintf("`%s`.`%s`", defaultDatabase, rightTable))
}
} else {
if rightTable.String() != "" {
tables = append(tables, fmt.Sprintf("`%s`.`%s`", rightDatabase, rightTable))
for _, tableRef := range common.JSONFind(jsonString, "TableRefs") {
for _, source := range common.JSONFind(tableRef, "Source") {
database := gjson.Get(source, "Schema.O")
table := gjson.Get(source, "Name.O")
if database.String() == "" {
if table.String() != "" {
tables = append(tables, fmt.Sprintf("`%s`.`%s`", defaultDatabase, table))
}
} else {
tables = append(tables, fmt.Sprintf("`%s`.`dual`", rightDatabase))
if table.String() != "" {
tables = append(tables, fmt.Sprintf("`%s`.`%s`", database, table))
} else {
tables = append(tables, fmt.Sprintf("`%s`.`dual`", database))
}
}
}
}
......
......@@ -64,6 +64,7 @@ func TestSchemaMetaInfo(t *testing.T) {
"select 1;",
"syntax error case",
"select * from ta join tb using (id)",
"select * from ta, tb limit 1",
}
err := common.GoldenDiff(func() {
for _, sql := range append(sqls, common.TestSQLs...) {
......
......@@ -204,7 +204,9 @@
"`hello`.`t`"
],
"C15BDF2C73B5B7ED": [
"`unknown`.`address`"
"`unknown`.`address`",
"`unknown`.`city`",
"`unknown`.`country`"
],
"C315BC4EE0F4E523": [
"`unknown`.inventory`"
......@@ -262,6 +264,7 @@
"`unknown`.`country`"
],
"FCD1ABF36F8CDAD7": [
"`unknown`.`city`",
"`unknown`.`country`"
],
"FE409EB794EE91CF": [
......@@ -474,7 +477,9 @@
"`hello`.`t`"
],
"C15BDF2C73B5B7ED": [
"`sakila`.`address`"
"`sakila`.`address`",
"`sakila`.`city`",
"`sakila`.`country`"
],
"C315BC4EE0F4E523": [
"`sakila`.inventory`"
......@@ -532,6 +537,7 @@
"`sakila`.`country`"
],
"FCD1ABF36F8CDAD7": [
"`sakila`.`city`",
"`sakila`.`country`"
],
"FE409EB794EE91CF": [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册