From 3435e1802588374ef1bf653821b2b76f3a46c024 Mon Sep 17 00:00:00 2001 From: tuuz Date: Mon, 6 Nov 2023 18:23:53 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8db.Where(?= =?UTF-8?q?"val")=E5=9C=A8=E5=8D=95=E7=BA=AF=E5=81=9A=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=97=B6=E4=BC=9A=E5=87=BA=E7=8E=B0identifier=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=202.=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8db.O?= =?UTF-8?q?rder**()=E6=A8=A1=E5=BC=8F=E6=97=B6=E4=BC=9A=E5=87=BA=E7=8E=B0i?= =?UTF-8?q?dentifier=E7=9A=84=E9=94=99=E8=AF=AF=203.=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=A4=8D=E6=9D=82Order=E6=9F=A5=E8=AF=A2=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E7=8E=B0identifier=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder_oracle.go | 53 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/builder_oracle.go b/builder_oracle.go index 4b674cb..9218e72 100644 --- a/builder_oracle.go +++ b/builder_oracle.go @@ -91,7 +91,7 @@ func (b *BuilderOracle) BuildQueryOra() (sqlStr string, args []interface{}, err tableName := b.BuildTable() sqlStr = fmt.Sprintf("SELECT %s%s FROM %s%s%s%s%s%s%s", b.BuildDistinct(), fieldsStr, tableName, join, where, b.BuildLimit(), b.BuildGroup(), b.BuildHaving(), b.BuildOrder()) - + fmt.Println("sqlstr1", sqlStr) // 批量取数据需嵌套写法 if b.GetLimit() > 0 { aliasNameA := "tabA" @@ -100,13 +100,21 @@ func (b *BuilderOracle) BuildQueryOra() (sqlStr string, args []interface{}, err startRow := (page-1)*b.GetLimit() + 1 endRow := page*b.GetLimit() + 1 - if fieldsStr == "*" { - fieldsStr = b.GetTable() + ".*, rownum r" - } else { - if b.GetGroup() == "" { - fieldsStr = fieldsStr + ", rownum r" - } - } + //if fieldsStr == "*" { + // fieldsStr = b.AddFieldQuotesOracle(b.GetTable()) + ".*, rownum r" + //} else { + // if b.GetGroup() == "" { + // fieldsStr = fieldsStr + ", rownum r" + // } + //} + + //if fieldsStr == "*" { + // fieldsStr = b.AddFieldQuotesOracle(b.GetTable()) + ".*, rownum r" + //} else { + // if b.GetGroup() == "" { + // fieldsStr = fieldsStr + ", rownum r" + // } + //} // 没有group by需要1层嵌套, 有group by需要2层嵌套 // 如果考虑orderby优化,还需要一层嵌套。目前未考虑 @@ -114,10 +122,12 @@ func (b *BuilderOracle) BuildQueryOra() (sqlStr string, args []interface{}, err sqlStr = fmt.Sprintf("SELECT %s%s FROM %s%s%s%s%s", b.BuildDistinct(), fieldsStr, tableName, join, where, b.BuildLimit(), b.BuildOrder()) - sqlStr = fmt.Sprintf("select * from (%s) %s where %s.r>=%s", - sqlStr, aliasNameA, aliasNameA, strconv.Itoa(startRow)) + //sqlStr = fmt.Sprintf("select * from (%s) %s where %s.r>=%s", + // sqlStr, aliasNameA, aliasNameA, strconv.Itoa(startRow)) + fmt.Println("sqlStr2", sqlStr, where, b.BuildLimit()) + } else { - sqlStr = fmt.Sprintf("SELECT %s%s FROM %s%s%s%s%s%s", b.BuildDistinct(), fieldsStr, + sqlStr = fmt.Sprintf("SELECT %s%s FROM %s%s%s%s%s%s GROUP BY ROWNUM", b.BuildDistinct(), fieldsStr, tableName, join, where, b.BuildGroup(), b.BuildHaving(), b.BuildOrder()) sqlStr = fmt.Sprintf( @@ -357,7 +367,26 @@ func (b *BuilderOracle) BuildHaving() string { // BuildOrder ... func (b *BuilderOracle) BuildOrder() string { - return b.BuilderDefault.BuildOrder() + str_arr1 := strings.Split(b.IOrm.GetOrder(), ",") + order := strings.Builder{} + for i, s := range str_arr1 { + if i > 0 { + order.WriteString(",") + } + temp_arr := strings.Split(s, " ") + for _, s2 := range temp_arr { + switch strings.TrimSpace(s2) { + case "desc", "asc": + order.WriteString(" " + strings.TrimSpace(s2)) + break + + default: + order.WriteString(b.AddFieldQuotesOracle(strings.TrimSpace(s2))) + break + } + } + } + return If(b.IOrm.GetOrder() == "", "", " ORDER BY "+order.String()).(string) } // BuildLimit ...