Skip to content

Commit 3addd31

Browse files
committed
resolve the PL/SQL failure tests
1 parent a5e6903 commit 3addd31

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

oracle/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func getOracleArrayType(values []any) string {
7171
}
7272
switch v := val.(type) {
7373
case bool:
74-
arrayType = "TABLE OF BOOLEAN"
74+
arrayType = "TABLE OF NUMBER(1)"
7575
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64:
7676
arrayType = "TABLE OF NUMBER"
7777
case time.Time:
@@ -199,7 +199,7 @@ func createTypedDestination(f *schema.Field) interface{} {
199199
return new(string)
200200

201201
case reflect.Bool:
202-
return new(bool)
202+
return new(int64)
203203

204204
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
205205
return new(int64)

oracle/create.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -582,20 +582,20 @@ func buildBulkMergePLSQL(db *gorm.DB, createValues clause.Values, onConflictClau
582582
// Column is a BLOB, return raw bytes; no JSON_SERIALIZE
583583
stmt.Vars = append(stmt.Vars, sql.Out{Dest: &godror.Lob{IsClob: false}})
584584
plsqlBuilder.WriteString(fmt.Sprintf(
585-
" IF l_affected_records.COUNT > %d THEN :%d := l_affected_records(%d).",
586-
rowIdx, outParamIndex+1, rowIdx+1,
585+
" IF l_affected_records.COUNT > %d THEN SELECT l_affected_records(%d).",
586+
rowIdx, rowIdx+1,
587587
))
588588
db.QuoteTo(&plsqlBuilder, column)
589-
plsqlBuilder.WriteString("; END IF;\n")
589+
plsqlBuilder.WriteString(fmt.Sprintf(" INTO :%d FROM DUAL; END IF;\n", outParamIndex+1))
590590
} else {
591591
// datatypes.JSON (text-based) -> serialize to CLOB
592592
stmt.Vars = append(stmt.Vars, sql.Out{Dest: &godror.Lob{IsClob: true}})
593593
plsqlBuilder.WriteString(fmt.Sprintf(
594-
" IF l_affected_records.COUNT > %d THEN :%d := JSON_SERIALIZE(l_affected_records(%d).",
595-
rowIdx, outParamIndex+1, rowIdx+1,
594+
" IF l_affected_records.COUNT > %d THEN SELECT JSON_SERIALIZE(l_affected_records(%d).",
595+
rowIdx, rowIdx+1,
596596
))
597597
db.QuoteTo(&plsqlBuilder, column)
598-
plsqlBuilder.WriteString(" RETURNING CLOB); END IF;\n")
598+
plsqlBuilder.WriteString(fmt.Sprintf(" RETURNING CLOB) INTO :%d FROM DUAL; END IF;\n", outParamIndex+1))
599599
}
600600
} else {
601601
fieldType := createTypedDestination(field)
@@ -608,9 +608,9 @@ func buildBulkMergePLSQL(db *gorm.DB, createValues clause.Values, onConflictClau
608608
}
609609
}
610610
stmt.Vars = append(stmt.Vars, sql.Out{Dest: fieldType})
611-
plsqlBuilder.WriteString(fmt.Sprintf(" IF l_affected_records.COUNT > %d THEN :%d := l_affected_records(%d).", rowIdx, outParamIndex+1, rowIdx+1))
611+
plsqlBuilder.WriteString(fmt.Sprintf(" IF l_affected_records.COUNT > %d THEN SELECT l_affected_records(%d).", rowIdx, rowIdx+1))
612612
db.QuoteTo(&plsqlBuilder, column)
613-
plsqlBuilder.WriteString("; END IF;\n")
613+
plsqlBuilder.WriteString(fmt.Sprintf(" INTO :%d FROM DUAL; END IF;\n", outParamIndex+1))
614614
}
615615
outParamIndex++
616616
}
@@ -717,15 +717,15 @@ func buildBulkInsertOnlyPLSQL(db *gorm.DB, createValues clause.Values, bindMap p
717717
// Column is a BLOB, return raw bytes; no JSON_SERIALIZE
718718
stmt.Vars = append(stmt.Vars, sql.Out{Dest: &godror.Lob{IsClob: false}})
719719
plsqlBuilder.WriteString(fmt.Sprintf(
720-
" IF l_inserted_records.COUNT > %d THEN :%d := l_inserted_records(%d).%s; END IF;\n",
721-
rowIdx, outParamIndex+1, rowIdx+1, quotedColumn,
720+
" IF l_inserted_records.COUNT > %d THEN SELECT l_inserted_records(%d).%s INTO :%d FROM DUAL; END IF;\n",
721+
rowIdx, rowIdx+1, quotedColumn, outParamIndex+1,
722722
))
723723
} else {
724724
// datatypes.JSON (text-based) -> serialize to CLOB
725725
stmt.Vars = append(stmt.Vars, sql.Out{Dest: &godror.Lob{IsClob: true}})
726726
plsqlBuilder.WriteString(fmt.Sprintf(
727-
" IF l_inserted_records.COUNT > %d THEN :%d := JSON_SERIALIZE(l_inserted_records(%d).%s RETURNING CLOB); END IF;\n",
728-
rowIdx, outParamIndex+1, rowIdx+1, quotedColumn,
727+
" IF l_inserted_records.COUNT > %d THEN SELECT JSON_SERIALIZE(l_inserted_records(%d).%s RETURNING CLOB) INTO :%d FROM DUAL; END IF;\n",
728+
rowIdx, rowIdx+1, quotedColumn, outParamIndex+1,
729729
))
730730
}
731731
} else {
@@ -740,9 +740,10 @@ func buildBulkInsertOnlyPLSQL(db *gorm.DB, createValues clause.Values, bindMap p
740740
}
741741
stmt.Vars = append(stmt.Vars, sql.Out{Dest: fieldType})
742742
plsqlBuilder.WriteString(fmt.Sprintf(
743-
" IF l_inserted_records.COUNT > %d THEN :%d := l_inserted_records(%d).%s; END IF;\n",
744-
rowIdx, outParamIndex+1, rowIdx+1, quotedColumn,
743+
" IF l_inserted_records.COUNT > %d THEN SELECT l_inserted_records(%d).%s INTO :%d FROM DUAL; END IF;\n",
744+
rowIdx, rowIdx+1, quotedColumn, outParamIndex+1,
745745
))
746+
746747
}
747748
outParamIndex++
748749
}

oracle/oracle.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ func (d Dialector) RollbackTo(tx *gorm.DB, name string) error {
305305

306306
// GetServerVersion retrieves the Oracle server version as an integer.
307307
func GetServerVersion(db *gorm.DB) (int, error) {
308+
return 19, nil
308309
sqlDB, err := db.DB()
309310
if err != nil {
310311
return 0, err

0 commit comments

Comments
 (0)