1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 05:20:55 +00:00

fix:return error after inserting data when primary key is string

This commit is contained in:
jianzhiyao 2020-08-11 16:53:31 +08:00
parent d05460237c
commit 9ca9535c48
4 changed files with 36 additions and 2 deletions

View File

@ -484,7 +484,12 @@ func (d *dbBase) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, names []s
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
} }

View File

@ -126,7 +126,12 @@ func (d *dbBaseOracle) InsertValue(q dbQuerier, mi *modelInfo, isMulti bool, nam
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
} }

View File

@ -412,6 +412,11 @@ type PtrPk struct {
Positive bool Positive bool
} }
type StrPk struct {
Id string `orm:"column(id);size(64);pk"`
Value string
}
var DBARGS = struct { var DBARGS = struct {
Driver string Driver string
Source string Source string

View File

@ -200,6 +200,7 @@ func TestSyncDb(t *testing.T) {
RegisterModel(new(IntegerPk)) RegisterModel(new(IntegerPk))
RegisterModel(new(UintPk)) RegisterModel(new(UintPk))
RegisterModel(new(PtrPk)) RegisterModel(new(PtrPk))
RegisterModel(new(StrPk))
err := RunSyncdb("default", true, Debug) err := RunSyncdb("default", true, Debug)
throwFail(t, err) throwFail(t, err)
@ -224,6 +225,7 @@ func TestRegisterModels(t *testing.T) {
RegisterModel(new(IntegerPk)) RegisterModel(new(IntegerPk))
RegisterModel(new(UintPk)) RegisterModel(new(UintPk))
RegisterModel(new(PtrPk)) RegisterModel(new(PtrPk))
RegisterModel(new(StrPk))
BootStrap() 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))
}