From e22f5b510f0cf8f7250e43ad72f55b9dc1c726af Mon Sep 17 00:00:00 2001 From: tuuz Date: Mon, 6 Nov 2023 18:43:20 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8DOracle-=E4=BD=BF=E7=94=A8db?= =?UTF-8?q?.Where("val")=E5=9C=A8=E5=8D=95=E7=BA=AF=E5=81=9A=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=97=B6=E4=BC=9A=E5=87=BA=E7=8E=B0identifier?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=202.=E4=BF=AE=E5=A4=8DOracle-?= =?UTF-8?q?=E4=BD=BF=E7=94=A8db.Order**()=E6=A8=A1=E5=BC=8F=E6=97=B6?= =?UTF-8?q?=E4=BC=9A=E5=87=BA=E7=8E=B0identifier=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=203.=E4=BF=AE=E5=A4=8DOracle-=E5=A4=8D=E6=9D=82Order?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=BC=9A=E5=87=BA=E7=8E=B0identifier?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=204.=E4=BF=AE=E5=A4=8DOracle-Count?= =?UTF-8?q?=E5=92=8CCounts=E6=96=B9=E6=B3=95=E9=94=99=E8=AF=AF=205.?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DOracle-Paginator=E4=BB=A5=E5=8F=8APaginatorWG?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder_oracle.go | 26 +++++++++++++------------- orm_query.go | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/builder_oracle.go b/builder_oracle.go index 9218e72..0c0642b 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) + //fmt.Println("sqlstr1", sqlStr) // 批量取数据需嵌套写法 if b.GetLimit() > 0 { aliasNameA := "tabA" @@ -108,25 +108,25 @@ func (b *BuilderOracle) BuildQueryOra() (sqlStr string, args []interface{}, err // } //} - //if fieldsStr == "*" { - // fieldsStr = b.AddFieldQuotesOracle(b.GetTable()) + ".*, rownum r" - //} else { - // if b.GetGroup() == "" { - // fieldsStr = fieldsStr + ", rownum r" - // } - //} - // 没有group by需要1层嵌套, 有group by需要2层嵌套 // 如果考虑orderby优化,还需要一层嵌套。目前未考虑 if b.GetGroup() == "" { - 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 %s%s FROM %s%s%s%s", b.BuildDistinct(), fieldsStr, + tableName, join, where, b.BuildOrder()) //sqlStr = fmt.Sprintf("select * from (%s) %s where %s.r>=%s", // sqlStr, aliasNameA, aliasNameA, strconv.Itoa(startRow)) - fmt.Println("sqlStr2", sqlStr, where, b.BuildLimit()) + //fmt.Println("sqlStr2", sqlStr, where) } else { + if fieldsStr == "*" { + fieldsStr = b.AddFieldQuotesOracle(b.GetTable()) + ".*, rownum r" + } else { + if b.GetGroup() == "" { + fieldsStr = fieldsStr + ", rownum r" + } + } + 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()) @@ -136,7 +136,7 @@ func (b *BuilderOracle) BuildQueryOra() (sqlStr string, args []interface{}, err strconv.Itoa(startRow)) } } - + //fmt.Println("final",sqlStr) //args = b.bindParams args = b.IOrm.GetBindValues() return diff --git a/orm_query.go b/orm_query.go index 16d1195..d156862 100644 --- a/orm_query.go +++ b/orm_query.go @@ -1,12 +1,12 @@ package gorose import ( - //"fmt" "github.com/gohouse/t" "math" "reflect" "strings" "sync" + //"fmt" ) // Select : select one or more rows , relation limit set @@ -63,7 +63,7 @@ func (dba *Orm) Count(args ...string) (int64, error) { if len(args) > 0 { fields = args[0] } - count, err := dba._unionBuild("count", fields) + count, err := dba._unionBuild("COUNT", fields) if count == nil { return 0, err } @@ -91,7 +91,7 @@ func (dba *Orm) Counts(count_fileds ...string) (int64, error) { return 0, err } dba.order = order - total_number, err := dba.Query(`SELECT count(*) as count from(`+sqls+`) as counts`, args...) + total_number, err := dba.Query(`SELECT COUNT(*) as COUNT from(`+sqls+`) as COUNTS`, args...) if err != nil { return 0, err } @@ -99,7 +99,7 @@ func (dba *Orm) Counts(count_fileds ...string) (int64, error) { if len(total_number) < 1 { return 0, err } - return t.New(total_number[0]["count"]).Int64(), err + return t.New(total_number[0]["COUNT"]).Int64(), err } }