AutoIncrement列带ID插入数据时没有Commit (#2264)
业务场景中,需要预留(1 ~ 100)的ID给系统规则使用。所以会先使用插入将AutoIncrement列的id偏移到一个特定的值(如:100),然后“带ID调用Insert插入系统规则”。 当带ID插入时,由于没有commit,会被rollback掉。 Reviewed-on: https://gitea.com/xorm/xorm/pulls/2264 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: brookechen <brookechen@noreply.gitea.io> Co-committed-by: brookechen <brookechen@noreply.gitea.io>
This commit is contained in:
parent
e6907e9a62
commit
190384b4cd
|
@ -353,15 +353,15 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if needCommit {
|
}
|
||||||
if err := session.Commit(); err != nil {
|
if needCommit {
|
||||||
return 0, err
|
if err := session.Commit(); err != nil {
|
||||||
}
|
return 0, err
|
||||||
}
|
|
||||||
if id == 0 {
|
|
||||||
return 0, errors.New("insert successfully but not returned id")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if id == 0 {
|
||||||
|
return 0, errors.New("insert successfully but not returned id")
|
||||||
|
}
|
||||||
|
|
||||||
defer handleAfterInsertProcessorFunc(bean)
|
defer handleAfterInsertProcessorFunc(bean)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue