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:
brookechen 2023-05-17 15:20:40 +08:00 committed by Lunny Xiao
parent e6907e9a62
commit 190384b4cd
1 changed files with 7 additions and 7 deletions

View File

@ -353,6 +353,7 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
}
if needCommit { if needCommit {
if err := session.Commit(); err != nil { if err := session.Commit(); err != nil {
return 0, err return 0, err
@ -361,7 +362,6 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
if id == 0 { if id == 0 {
return 0, errors.New("insert successfully but not returned id") return 0, errors.New("insert successfully but not returned id")
} }
}
defer handleAfterInsertProcessorFunc(bean) defer handleAfterInsertProcessorFunc(bean)