From 81b1478ecf36dbbfe12758839886d3c5e502f2a4 Mon Sep 17 00:00:00 2001 From: Jim Lambert Date: Sat, 15 Feb 2020 16:11:36 -0500 Subject: [PATCH] refactor to use OraDialect interface --- callback_create.go | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/callback_create.go b/callback_create.go index 40bb516d..67b1e36f 100644 --- a/callback_create.go +++ b/callback_create.go @@ -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 }