1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 04:00:54 +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,9 +489,11 @@ func (d *dbBase) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, names []s
lastInsertId, err := res.LastInsertId() lastInsertId, err := res.LastInsertId()
if err != nil { if err != nil {
DebugLog.Println(ErrLastInsertIdUnavailable, ':', err) DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
} return lastInsertId, ErrLastInsertIdUnavailable
}else{
return lastInsertId, nil return lastInsertId, nil
} }
}
return 0, err return 0, err
} }
row := q.QueryRow(query, values...) row := q.QueryRow(query, values...)
@ -595,9 +597,11 @@ func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, a
lastInsertId, err := res.LastInsertId() lastInsertId, err := res.LastInsertId()
if err != nil { if err != nil {
DebugLog.Println(ErrLastInsertIdUnavailable, ':', err) DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
} return lastInsertId, ErrLastInsertIdUnavailable
}else{
return lastInsertId, nil return lastInsertId, nil
} }
}
return 0, err return 0, err
} }

View File

@ -168,9 +168,11 @@ func (d *dbBaseMysql) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Val
lastInsertId, err := res.LastInsertId() lastInsertId, err := res.LastInsertId()
if err != nil { if err != nil {
DebugLog.Println(ErrLastInsertIdUnavailable, ':', err) DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
} return lastInsertId, ErrLastInsertIdUnavailable
}else{
return lastInsertId, nil return lastInsertId, nil
} }
}
return 0, err return 0, err
} }

View File

@ -154,9 +154,11 @@ func (d *dbBaseOracle) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, nam
lastInsertId, err := res.LastInsertId() lastInsertId, err := res.LastInsertId()
if err != nil { if err != nil {
DebugLog.Println(ErrLastInsertIdUnavailable, ':', err) DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
} return lastInsertId, ErrLastInsertIdUnavailable
}else{
return lastInsertId, nil return lastInsertId, nil
} }
}
return 0, err return 0, err
} }
row := q.QueryRow(query, values...) row := q.QueryRow(query, values...)

View File

@ -2537,7 +2537,9 @@ func TestStrPkInsert(t *testing.T) {
var err error var err error
_, err = dORM.Insert(strPk) _, err = dORM.Insert(strPk)
if err != ErrLastInsertIdUnavailable {
throwFailNow(t, AssertIs(err, nil)) throwFailNow(t, AssertIs(err, nil))
}
var vForTesting StrPk var vForTesting StrPk
err = dORM.QueryTable(new(StrPk)).Filter(`id`, pk).One(&vForTesting) err = dORM.QueryTable(new(StrPk)).Filter(`id`, pk).One(&vForTesting)
@ -2554,6 +2556,7 @@ func TestStrPkInsert(t *testing.T) {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
if err.Error() == "postgres version must 9.5 or higher" || err.Error() == "`sqlite3` nonsupport InsertOrUpdate in beego" { if err.Error() == "postgres version must 9.5 or higher" || err.Error() == "`sqlite3` nonsupport InsertOrUpdate in beego" {
} else if err == ErrLastInsertIdUnavailable {
} else { } else {
throwFailNow(t, err) throwFailNow(t, err)
} }