diff --git a/pkg/orm/db.go b/pkg/orm/db.go index 573247f0..dc4b5a3f 100644 --- a/pkg/orm/db.go +++ b/pkg/orm/db.go @@ -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 } diff --git a/pkg/orm/db_oracle.go b/pkg/orm/db_oracle.go index fa49e16b..91a30f81 100644 --- a/pkg/orm/db_oracle.go +++ b/pkg/orm/db_oracle.go @@ -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 } diff --git a/pkg/orm/models_test.go b/pkg/orm/models_test.go index 1368c150..b53da05b 100644 --- a/pkg/orm/models_test.go +++ b/pkg/orm/models_test.go @@ -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 diff --git a/pkg/orm/orm_test.go b/pkg/orm/orm_test.go index a7a0a2c1..fd752a94 100644 --- a/pkg/orm/orm_test.go +++ b/pkg/orm/orm_test.go @@ -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)) +} +