mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 17:00:50 +00:00
fix:return error after inserting data when primary key is string
This commit is contained in:
parent
d05460237c
commit
9ca9535c48
@ -484,7 +484,12 @@ func (d *dbBase) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, names []s
|
||||
if isMulti {
|
||||
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
|
||||
}
|
||||
|
@ -126,7 +126,12 @@ func (d *dbBaseOracle) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, nam
|
||||
if isMulti {
|
||||
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
|
||||
}
|
||||
|
@ -412,6 +412,11 @@ type PtrPk struct {
|
||||
Positive bool
|
||||
}
|
||||
|
||||
type StrPk struct {
|
||||
Id string `orm:"column(id);size(64);pk"`
|
||||
Value string
|
||||
}
|
||||
|
||||
var DBARGS = struct {
|
||||
Driver string
|
||||
Source string
|
||||
|
@ -200,6 +200,7 @@ func TestSyncDb(t *testing.T) {
|
||||
RegisterModel(new(IntegerPk))
|
||||
RegisterModel(new(UintPk))
|
||||
RegisterModel(new(PtrPk))
|
||||
RegisterModel(new(StrPk))
|
||||
|
||||
err := RunSyncdb("default", true, Debug)
|
||||
throwFail(t, err)
|
||||
@ -224,6 +225,7 @@ func TestRegisterModels(t *testing.T) {
|
||||
RegisterModel(new(IntegerPk))
|
||||
RegisterModel(new(UintPk))
|
||||
RegisterModel(new(PtrPk))
|
||||
RegisterModel(new(StrPk))
|
||||
|
||||
BootStrap()
|
||||
|
||||
@ -2487,4 +2489,21 @@ func TestInsertOrUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrPkInsert(t *testing.T) {
|
||||
RegisterModel(new(StrPk))
|
||||
value := `StrPkValues(*56`
|
||||
strPk := &StrPk{
|
||||
Id: "1",
|
||||
Value: value,
|
||||
}
|
||||
|
||||
var err error
|
||||
_, err = dORM.Insert(strPk)
|
||||
throwFailNow(t, AssertIs(err, nil))
|
||||
|
||||
var vForTesting StrPk
|
||||
err = dORM.QueryTable(new(StrPk)).Filter(`id`, `1`).One(&vForTesting)
|
||||
throwFailNow(t, AssertIs(err, nil))
|
||||
throwFailNow(t, AssertIs(vForTesting.Value, value))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user