diff --git a/pkg/orm/db.go b/pkg/orm/db.go index 2477b132..0b6d8ac1 100644 --- a/pkg/orm/db.go +++ b/pkg/orm/db.go @@ -489,8 +489,10 @@ func (d *dbBase) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, names []s lastInsertId, err := res.LastInsertId() if err != nil { DebugLog.Println(ErrLastInsertIdUnavailable, ':', err) + return lastInsertId, ErrLastInsertIdUnavailable + }else{ + return lastInsertId, nil } - return lastInsertId, nil } return 0, err } @@ -595,8 +597,10 @@ func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, a lastInsertId, err := res.LastInsertId() if err != nil { DebugLog.Println(ErrLastInsertIdUnavailable, ':', err) + return lastInsertId, ErrLastInsertIdUnavailable + }else{ + return lastInsertId, nil } - return lastInsertId, nil } return 0, err } diff --git a/pkg/orm/db_mysql.go b/pkg/orm/db_mysql.go index 11665fb2..efa5a50b 100644 --- a/pkg/orm/db_mysql.go +++ b/pkg/orm/db_mysql.go @@ -168,8 +168,10 @@ func (d *dbBaseMysql) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Val lastInsertId, err := res.LastInsertId() if err != nil { DebugLog.Println(ErrLastInsertIdUnavailable, ':', err) + return lastInsertId, ErrLastInsertIdUnavailable + }else{ + return lastInsertId, nil } - return lastInsertId, nil } return 0, err } diff --git a/pkg/orm/db_oracle.go b/pkg/orm/db_oracle.go index 5177fb89..d384d33e 100644 --- a/pkg/orm/db_oracle.go +++ b/pkg/orm/db_oracle.go @@ -154,8 +154,10 @@ func (d *dbBaseOracle) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, nam lastInsertId, err := res.LastInsertId() if err != nil { DebugLog.Println(ErrLastInsertIdUnavailable, ':', err) + return lastInsertId, ErrLastInsertIdUnavailable + }else{ + return lastInsertId, nil } - return lastInsertId, nil } return 0, err } diff --git a/pkg/orm/orm_test.go b/pkg/orm/orm_test.go index 0d4451cd..c759309e 100644 --- a/pkg/orm/orm_test.go +++ b/pkg/orm/orm_test.go @@ -2537,7 +2537,9 @@ func TestStrPkInsert(t *testing.T) { var err error _, err = dORM.Insert(strPk) - throwFailNow(t, AssertIs(err, nil)) + if err != ErrLastInsertIdUnavailable { + throwFailNow(t, AssertIs(err, nil)) + } var vForTesting StrPk err = dORM.QueryTable(new(StrPk)).Filter(`id`, pk).One(&vForTesting) @@ -2554,6 +2556,7 @@ func TestStrPkInsert(t *testing.T) { if err != nil { fmt.Println(err) if err.Error() == "postgres version must 9.5 or higher" || err.Error() == "`sqlite3` nonsupport InsertOrUpdate in beego" { + } else if err == ErrLastInsertIdUnavailable { } else { throwFailNow(t, err) }