fix: begin transaction fail, rollback panic (#6365)

This commit is contained in:
东方上人 2023-05-31 19:21:51 +08:00 committed by GitHub
parent 26663ab9bf
commit 740f2be453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package gorm
import (
"context"
"database/sql"
"reflect"
"sync"
)
@ -163,14 +164,14 @@ type PreparedStmtTX struct {
}
func (tx *PreparedStmtTX) Commit() error {
if tx.Tx != nil {
if tx.Tx != nil && !reflect.ValueOf(tx.Tx).IsNil() {
return tx.Tx.Commit()
}
return ErrInvalidTransaction
}
func (tx *PreparedStmtTX) Rollback() error {
if tx.Tx != nil {
if tx.Tx != nil && !reflect.ValueOf(tx.Tx).IsNil() {
return tx.Tx.Rollback()
}
return ErrInvalidTransaction