Skip to content

Commit

Permalink
🐛 修复 CLOB 类型字段内容长度过长时报 ORA-01461 的问题
Browse files Browse the repository at this point in the history
ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值

Fix #10

Signed-off-by: liutianqi <[email protected]>
  • Loading branch information
iTanken committed Jan 11, 2024
1 parent 1853e2e commit 730769f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 7 additions & 3 deletions oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,17 @@ 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 {
val = ptrDereference(val)
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...)
Expand Down

0 comments on commit 730769f

Please sign in to comment.