关于事务失败不回滚 #15
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No Assignees
1 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: xorm/tests#15
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Author: @xubing
我在用事务的时候,第一条插入成功,第二条插入失败的时候,执行回滚后,第一条数据还在。
我这个测试的时候,使用的是postgresql,其中定义了一个json字段。执行的错误提示是json字段错误。
下面是测试代码。如果我把
user := User{Id:login.Id } 换成
user := User{Id:login.Id ,Photos:"[]"}都可以插入成功。
`
package main
import (
"github.com/go-xorm/xorm"
_ "github.com/lib/pq"
"fmt"
"github.com/xormplus/core"
)
type Login struct {
Id int64
xorm:"not null pk autoincr INTEGER"
CreatedAt time.Time
xorm:"TIMESTAMPZ created "
Name string
}
type User struct {
Id int64
xorm:"not null pk INTEGER"
Photos string
xorm:"JSON"
}
//xorm
func main() {
}
`
Author: @xubing
发觉事务的回滚没有用。我现在插入一条数据后,不论成功和失败,我都回滚。结果这条数,仍旧存在。
`
session := FFDB.NewSession()
login := Login{Name:"TestName"}
_,err = session.InsertOne(&login)
session.Rollback()
session.Close()
`
Author: @lunny
嗯。要先调
session.Begin()
,最后要调session.Commit()
,Rollback()
一般可以不用调,调用session.Close
的时候,如果没调过session.Commit()
,则Rollback()
会被自动调。