mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 17:30:50 +00:00
Merge pull request #4150 from jianzhiyao/frt/fix_3830
fix:return error after inserting data when primary key is string
This commit is contained in:
commit
5bc8d90d7f
@ -485,7 +485,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
|
||||
}
|
||||
|
@ -150,7 +150,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
|
||||
}
|
||||
|
@ -421,6 +421,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
|
||||
|
@ -202,6 +202,7 @@ func TestSyncDb(t *testing.T) {
|
||||
RegisterModel(new(UintPk))
|
||||
RegisterModel(new(PtrPk))
|
||||
RegisterModel(new(Index))
|
||||
RegisterModel(new(StrPk))
|
||||
|
||||
err := RunSyncdb("default", true, Debug)
|
||||
throwFail(t, err)
|
||||
@ -227,6 +228,7 @@ func TestRegisterModels(t *testing.T) {
|
||||
RegisterModel(new(UintPk))
|
||||
RegisterModel(new(PtrPk))
|
||||
RegisterModel(new(Index))
|
||||
RegisterModel(new(StrPk))
|
||||
|
||||
BootStrap()
|
||||
|
||||
@ -2523,3 +2525,22 @@ func TestInsertOrUpdate(t *testing.T) {
|
||||
throwFailNow(t, AssertIs((((user2.Status+1)-1)*3)/3, test.Status))
|
||||
}
|
||||
}
|
||||
|
||||
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