From a1a90c8f79f5c9ee1c6e928e5aac7bde752cb9d2 Mon Sep 17 00:00:00 2001 From: liutianqi Date: Tue, 30 Jan 2024 17:43:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20=E4=BF=AE=E6=94=B9=20Oracle12c?= =?UTF-8?q?=20=E5=8F=8A=E4=BB=A5=E4=B8=8A=E7=89=88=E6=9C=AC=20limit=20?= =?UTF-8?q?=E5=92=8C=20offset=20=E4=BD=BF=E7=94=A8=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref: go-gorm/gorm/pull/6806 Signed-off-by: liutianqi --- oracle.go | 4 ++-- oracle_test.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/oracle.go b/oracle.go index 012e231..9e74989 100644 --- a/oracle.go +++ b/oracle.go @@ -298,12 +298,12 @@ func (d Dialector) RewriteLimit(c clause.Clause, builder clause.Builder) { if offset := limit.Offset; offset > 0 { _, _ = builder.WriteString(" OFFSET ") - _, _ = builder.WriteString(strconv.Itoa(offset)) + builder.AddVar(builder, offset) _, _ = builder.WriteString(" ROWS") } if hasLimit { _, _ = builder.WriteString(" FETCH NEXT ") - _, _ = builder.WriteString(strconv.Itoa(limitRows)) + builder.AddVar(builder, limitRows) _, _ = builder.WriteString(" ROWS ONLY") } } diff --git a/oracle_test.go b/oracle_test.go index c12a257..51d2ca2 100644 --- a/oracle_test.go +++ b/oracle_test.go @@ -2,6 +2,7 @@ package oracle import ( "database/sql" + "encoding/json" "log" "os" "reflect" @@ -134,6 +135,26 @@ func TestCountLimit0(t *testing.T) { } } +func TestLimit(t *testing.T) { + db, err := dbNamingCase, dbErrors[0] + if err != nil { + t.Fatal(err) + } + if db == nil { + t.Log("db is nil!") + return + } + TestMergeCreate(t) + + var data []TestTableUser + result := db.Model(&TestTableUser{}).Limit(10).Find(&data) + if err = result.Error; err != nil { + t.Fatal(err) + } + dataBytes, _ := json.MarshalIndent(data, "", " ") + t.Logf("Limit(10) got size = %d, data = %s", len(data), dataBytes) +} + func TestAddSessionParams(t *testing.T) { db, err := dbIgnoreCase, dbErrors[1] if err != nil {