From 524a892480c23e82b8d59ad54763ff44bedc3d5f Mon Sep 17 00:00:00 2001 From: hoteas Date: Mon, 8 Aug 2022 04:34:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/makecode.go | 8 ++++++++ db/hotimedb.go | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) 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) + " " + }() + } } }