refactor to use OraDialect interface

This commit is contained in:
Jim Lambert 2020-02-15 16:11:36 -05:00
parent 37acd305bf
commit 81b1478ecf

View File

@ -1,9 +1,7 @@
package gorm package gorm
import ( import (
"database/sql"
"fmt" "fmt"
"reflect"
"strings" "strings"
) )
@ -146,30 +144,8 @@ func createCallback(scope *Scope) {
return return
} }
// this is very specific to how the oci8 driver handles the last insert id via a sql.Out parameter if ora, ok := scope.Dialect().(OraDialect); ok {
if scope.Dialect().GetName() == "oci8" { ora.CreateWithReturningInto(scope)
var stringId string
var intId uint32
primaryIsString := false
out := sql.Out{
Dest: &intId,
}
if primaryField.Field.Kind() == reflect.String {
out = sql.Out{
Dest: &stringId,
}
primaryIsString = true
}
scope.SQLVars = append(scope.SQLVars, out)
scope.SQL = fmt.Sprintf("%s returning %s into :%d", scope.SQL, scope.Quote(primaryField.DBName), len(scope.SQLVars))
if result, err := scope.SQLDB().Exec(scope.SQL, scope.SQLVars...); scope.Err(err) == nil {
scope.db.RowsAffected, _ = result.RowsAffected()
if primaryIsString {
scope.Err(primaryField.Set(stringId))
} else {
scope.Err(primaryField.Set(intId))
}
}
return return
} }