Skip to content

Commit 6ca3ece

Browse files
committed
Merge branch 'main' into fix_issue_81
2 parents e98e573 + 016821e commit 6ca3ece

File tree

11 files changed

+1108
-20
lines changed

11 files changed

+1108
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To use ODPI-C with Godror, you’ll need to install the Oracle Instant Client on
1010

1111
Follow the steps on [this page](https://odpi-c.readthedocs.io/en/latest/user_guide/installation.html) complete the installation.
1212

13-
After that, use a logfmt-encoded parameter list to specify the instanct client directory in the `dataSourceName` when you connect to the database. For example:
13+
After that, use a logfmt-encoded parameter list to specify the instant client directory in the `dataSourceName` when you connect to the database. For example:
1414

1515
```go
1616
dsn := `user="scott" password="tiger"

oracle/common.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import (
5353
)
5454

5555
// Helper function to get Oracle array type for a field
56-
func getOracleArrayType(field *schema.Field) string {
56+
func getOracleArrayType(field *schema.Field, values []any) string {
5757
switch field.DataType {
5858
case schema.Bool:
5959
return "TABLE OF NUMBER(1)"
@@ -64,6 +64,14 @@ func getOracleArrayType(field *schema.Field) string {
6464
case schema.String:
6565
if field.Size > 0 && field.Size <= 4000 {
6666
return fmt.Sprintf("TABLE OF VARCHAR2(%d)", field.Size)
67+
} else {
68+
for _, value := range values {
69+
if strValue, ok := value.(string); ok {
70+
if len(strValue) > 4000 {
71+
return "TABLE OF CLOB"
72+
}
73+
}
74+
}
6775
}
6876
return "TABLE OF VARCHAR2(4000)"
6977
case schema.Time:

oracle/create.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func buildBulkMergePLSQL(db *gorm.DB, createValues clause.Values, onConflictClau
296296
for i, column := range createValues.Columns {
297297
var arrayType string
298298
if field := findFieldByDBName(schema, column.Name); field != nil {
299-
arrayType = getOracleArrayType(field)
299+
arrayType = getOracleArrayType(field, pluck(createValues.Values, i))
300300
} else {
301301
arrayType = "TABLE OF VARCHAR2(4000)"
302302
}
@@ -579,7 +579,7 @@ func buildBulkInsertOnlyPLSQL(db *gorm.DB, createValues clause.Values) {
579579
for i, column := range createValues.Columns {
580580
var arrayType string
581581
if field := findFieldByDBName(schema, column.Name); field != nil {
582-
arrayType = getOracleArrayType(field)
582+
arrayType = getOracleArrayType(field, pluck(createValues.Values, i))
583583
} else {
584584
arrayType = "TABLE OF VARCHAR2(4000)"
585585
}
@@ -1007,3 +1007,12 @@ func sanitizeCreateValuesForBulkArrays(stmt *gorm.Statement, cv *clause.Values)
10071007
}
10081008
}
10091009
}
1010+
1011+
// pluck extracts the values at index col from a slice of arrays []T.
1012+
func pluck[T any, N int](data [][]T, col int) []T {
1013+
out := make([]T, len(data))
1014+
for i := range data {
1015+
out[i] = data[i][col]
1016+
}
1017+
return out
1018+
}

oracle/migrator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (m Migrator) DropColumn(value interface{}, name string) error {
310310
}
311311

312312
return m.DB.Exec(
313-
"ALTER TABLE ? DROP ?",
313+
"ALTER TABLE ? DROP COLUMN ?",
314314
clause.Table{Name: stmt.Schema.Table},
315315
clause.Column{Name: name},
316316
).Error

0 commit comments

Comments
 (0)