1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-21 17:50:53 +00:00

add ErrLastInsertIdUnavailable

This commit is contained in:
jianzhiyao 2020-08-14 15:09:47 +08:00
parent 739b8bab0c
commit 7b899aa9af
4 changed files with 16 additions and 5 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}