From afff9b85fb2ca4e7d5d36b1846647806be88287f Mon Sep 17 00:00:00 2001 From: liutianqi Date: Thu, 11 Jan 2024 17:01:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=20CLOB=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5=E5=86=85=E5=AE=B9=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E8=BF=87=E9=95=BF=E6=97=B6=E6=8A=A5=20ORA-01461=20?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值 Fix #10 Signed-off-by: liutianqi --- create.go | 5 +++++ oracle.go | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/create.go b/create.go index b341743..1a481ba 100644 --- a/create.go +++ b/create.go @@ -4,6 +4,7 @@ import ( "database/sql" "reflect" + "github.com/sijms/go-ora/v2" "gorm.io/gorm" "gorm.io/gorm/callbacks" "gorm.io/gorm/clause" @@ -205,6 +206,10 @@ func convertValue(val interface{}) interface{} { } else { val = 0 } + case string: + if len(v) > 2000 { + val = go_ora.Clob{String: v, Valid: true} + } default: val = convertCustomType(val) } diff --git a/oracle.go b/oracle.go index ff649c7..a921166 100644 --- a/oracle.go +++ b/oracle.go @@ -404,13 +404,16 @@ func (d Dialector) QuoteTo(writer clause.Writer, str string) { var numericPlaceholder = regexp.MustCompile(`:(\d+)`) func (d Dialector) Explain(sql string, vars ...interface{}) string { - for idx, v := range vars { - if b, ok := ptrDereference(v).(bool); ok { - if b { + for idx, val := range vars { + switch v := ptrDereference(val).(type) { + case bool: + if v { vars[idx] = 1 } else { vars[idx] = 0 } + case go_ora.Clob: + vars[idx] = v.String } } return logger.ExplainSQL(sql, numericPlaceholder, `'`, vars...)