refactor to use OraDialect interface
This commit is contained in:
parent
37acd305bf
commit
81b1478ecf
@ -1,9 +1,7 @@
|
||||
package gorm
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -146,30 +144,8 @@ func createCallback(scope *Scope) {
|
||||
return
|
||||
}
|
||||
|
||||
// this is very specific to how the oci8 driver handles the last insert id via a sql.Out parameter
|
||||
if scope.Dialect().GetName() == "oci8" {
|
||||
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))
|
||||
}
|
||||
}
|
||||
if ora, ok := scope.Dialect().(OraDialect); ok {
|
||||
ora.CreateWithReturningInto(scope)
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user