diff --git a/finisher_api.go b/finisher_api.go index 982277d0..92773d9e 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -617,8 +617,7 @@ func (db *DB) Transaction(fc func(tx *DB) error, opts ...*sql.TxOptions) (err er if committer, ok := db.Statement.ConnPool.(TxCommitter); ok && committer != nil { // nested transaction - if !db.DisableNestedTransaction && (!db.PrepareStmt || - (db.PrepareStmt && !db.DisablePrepareNestedTransaction)) { + if !db.DisableNestedTransaction && !db.PrepareStmt { err = db.SavePoint(fmt.Sprintf("sp%p", fc)).Error if err != nil { return diff --git a/gorm.go b/gorm.go index 3ef228ec..37595ddd 100644 --- a/gorm.go +++ b/gorm.go @@ -41,8 +41,6 @@ type Config struct { IgnoreRelationshipsWhenMigrating bool // DisableNestedTransaction disable nested transaction DisableNestedTransaction bool - // DisablePrepareNestedTransaction disable nested transaction in prepare statement - DisablePrepareNestedTransaction bool // AllowGlobalUpdate allow global update AllowGlobalUpdate bool // QueryFields executes the SQL query with all fields of the table diff --git a/tests/prepared_stmt_test.go b/tests/prepared_stmt_test.go index 34ab7cb0..6aadeb25 100644 --- a/tests/prepared_stmt_test.go +++ b/tests/prepared_stmt_test.go @@ -62,7 +62,7 @@ func TestPreparedStmt(t *testing.T) { tx1.Transaction(func(tx2 *gorm.DB) error { tx2.Create(&users[1]) - return errors.New("rollback user2") // Rollback user3 + return errors.New("rollback user2") // not support prepare savepoint }) tx1.Transaction(func(tx2 *gorm.DB) error { @@ -76,7 +76,7 @@ func TestPreparedStmt(t *testing.T) { var psUsers []User err = tx.Where("name like ?", "prepared_stmt_transaction%").Find(&psUsers).Error AssertEqual(t, nil, err) - AssertEqual(t, 2, len(psUsers)) + AssertEqual(t, 3, len(psUsers)) } func TestPreparedStmtFromTransaction(t *testing.T) {