From 0112f25f24cc820b662d15547b2ca2eaa0504567 Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 8 Nov 2016 19:11:00 +0900 Subject: [PATCH] fixed h2 insert --- orm/callback_create.go | 16 +++++++++++++--- orm/dialect_h2.go | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/orm/callback_create.go b/orm/callback_create.go index b300166..b80abe3 100644 --- a/orm/callback_create.go +++ b/orm/callback_create.go @@ -117,10 +117,20 @@ func createCallback(scope *Scope) { } } } else { - if err := scope.SQLDB().QueryRow(scope.SQL, scope.SQLVars...).Scan(primaryField.Field.Addr().Interface()); scope.Err(err) == nil { - primaryField.IsBlank = false - scope.db.RowsAffected = 1 + + if scope.Dialect().GetName() == "h2" { + _, err := scope.SQLDB().Exec(scope.SQL, scope.SQLVars...) + if scope.Err(err) == nil { + primaryField.IsBlank = false + scope.db.RowsAffected = 1 + } + } else { + if err := scope.SQLDB().QueryRow(scope.SQL, scope.SQLVars...).Scan(primaryField.Field.Addr().Interface()); scope.Err(err) == nil { + primaryField.IsBlank = false + scope.db.RowsAffected = 1 + } } + } } } diff --git a/orm/dialect_h2.go b/orm/dialect_h2.go index dd00525..0f14f8b 100644 --- a/orm/dialect_h2.go +++ b/orm/dialect_h2.go @@ -114,12 +114,13 @@ func (s h2) CurrentDatabase() (name string) { func (s h2) LastInsertIDReturningSuffix(tableName, key string) string { //return fmt.Sprintf("RETURNING %v.%v", tableName, key) - return fmt.Sprintf(" ") + return fmt.Sprintf(" ; ") } func (h2) SupportLastInsertID() bool { return false } + // //func isByteArrayOrSlice(value reflect.Value) bool { // return (value.Kind() == reflect.Array || value.Kind() == reflect.Slice) && value.Type().Elem() == reflect.TypeOf(uint8(0))