diff --git a/code/makecode.go b/code/makecode.go index 05fd706..aca2f3d 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -836,9 +836,17 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db * } } else { + reStr += table + "." + v.GetString("name") + "," } + if v["name"] == "parent_id" && v.GetString("link") != "" { + leftJoin["[>]"+v.GetString("link")+" selfParent"] = + "selfParent.id=" + + v.GetString("link") + "." + v.GetString("name") + reStr += "selfParent." + v.GetString("value") + " AS " + v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + "," + } + //准备加入索引权限 if v.GetString("link") != "" && userData != nil && diff --git a/db/hotimedb.go b/db/hotimedb.go index 80f7800..6292c4c 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -634,15 +634,42 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map { v := testQuData[k] switch Substr(k, 0, 3) { case "[>]": - query += " LEFT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string) + " " + func() { + table := Substr(k, 3, len(k)-3) + if !strings.Contains(table, " ") { + table = "`" + table + "`" + } + query += " LEFT JOIN " + table + " ON " + v.(string) + " " + }() case "[<]": - query += " RIGHT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string) + " " + func() { + table := Substr(k, 3, len(k)-3) + if !strings.Contains(table, " ") { + table = "`" + table + "`" + } + query += " RIGHT JOIN " + table + " ON " + v.(string) + " " + }() + } switch Substr(k, 0, 4) { case "[<>]": - query += " FULL JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string) + " " + func() { + table := Substr(k, 4, len(k)-4) + if !strings.Contains(table, " ") { + table = "`" + table + "`" + } + query += " FULL JOIN " + table + " ON " + v.(string) + " " + }() + case "[><]": - query += " INNER JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string) + " " + func() { + table := Substr(k, 4, len(k)-4) + if !strings.Contains(table, " ") { + table = "`" + table + "`" + } + query += " INNER JOIN " + table + " ON " + v.(string) + " " + }() + } } }