mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 04:21:00 +00:00
fix:return error when calling `InsertOrUpdate
` is successful with string primary key
This commit is contained in:
parent
d6a2621b3c
commit
7ce0fde171
@ -486,7 +486,7 @@ func (d *dbBase) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, names []s
|
|||||||
return res.RowsAffected()
|
return res.RowsAffected()
|
||||||
}
|
}
|
||||||
|
|
||||||
lastInsertId, err:=res.LastInsertId()
|
lastInsertId, err := res.LastInsertId()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
DebugLog.Println("[WARN] return LastInsertId error:", err)
|
DebugLog.Println("[WARN] return LastInsertId error:", err)
|
||||||
}
|
}
|
||||||
@ -591,7 +591,12 @@ func (d *dbBase) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Value, a
|
|||||||
if isMulti {
|
if isMulti {
|
||||||
return res.RowsAffected()
|
return res.RowsAffected()
|
||||||
}
|
}
|
||||||
return res.LastInsertId()
|
|
||||||
|
lastInsertId, err := res.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
DebugLog.Println("[WARN] return LastInsertId error:", err)
|
||||||
|
}
|
||||||
|
return lastInsertId, nil
|
||||||
}
|
}
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,12 @@ func (d *dbBaseMysql) InsertOrUpdate(q dbQuerier, mi *modelInfo, ind reflect.Val
|
|||||||
if isMulti {
|
if isMulti {
|
||||||
return res.RowsAffected()
|
return res.RowsAffected()
|
||||||
}
|
}
|
||||||
return res.LastInsertId()
|
|
||||||
|
lastInsertId, err := res.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
DebugLog.Println("[WARN] return LastInsertId error:", err)
|
||||||
|
}
|
||||||
|
return lastInsertId, nil
|
||||||
}
|
}
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -2528,9 +2528,10 @@ func TestInsertOrUpdate(t *testing.T) {
|
|||||||
|
|
||||||
func TestStrPkInsert(t *testing.T) {
|
func TestStrPkInsert(t *testing.T) {
|
||||||
RegisterModel(new(StrPk))
|
RegisterModel(new(StrPk))
|
||||||
|
pk := `1`
|
||||||
value := `StrPkValues(*56`
|
value := `StrPkValues(*56`
|
||||||
strPk := &StrPk{
|
strPk := &StrPk{
|
||||||
Id: "1",
|
Id: pk,
|
||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2539,8 +2540,21 @@ func TestStrPkInsert(t *testing.T) {
|
|||||||
throwFailNow(t, AssertIs(err, nil))
|
throwFailNow(t, AssertIs(err, nil))
|
||||||
|
|
||||||
var vForTesting StrPk
|
var vForTesting StrPk
|
||||||
err = dORM.QueryTable(new(StrPk)).Filter(`id`, `1`).One(&vForTesting)
|
err = dORM.QueryTable(new(StrPk)).Filter(`id`, pk).One(&vForTesting)
|
||||||
throwFailNow(t, AssertIs(err, nil))
|
throwFailNow(t, AssertIs(err, nil))
|
||||||
throwFailNow(t, AssertIs(vForTesting.Value, value))
|
throwFailNow(t, AssertIs(vForTesting.Value, value))
|
||||||
|
|
||||||
|
value2 := `s8s5da7as`
|
||||||
|
strPkForUpsert := &StrPk{
|
||||||
|
Id: pk,
|
||||||
|
Value: value2,
|
||||||
|
}
|
||||||
|
_, err = dORM.InsertOrUpdate(strPkForUpsert, `id`)
|
||||||
|
throwFailNow(t, AssertIs(err, nil))
|
||||||
|
|
||||||
|
var vForTesting2 StrPk
|
||||||
|
err = dORM.QueryTable(new(StrPk)).Filter(`id`, pk).One(&vForTesting2)
|
||||||
|
throwFailNow(t, AssertIs(err, nil))
|
||||||
|
throwFailNow(t, AssertIs(vForTesting2.Value, value2))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user