mirror of
https://github.com/astaxie/beego.git
synced 2024-12-25 17:20:49 +00:00
add support for pointer fields of structs to method QueryRows()
This commit is contained in:
parent
d0c744ae6a
commit
af4464ce58
@ -191,6 +191,14 @@ func (o *rawSet) setFieldValue(ind reflect.Value, value interface{}) {
|
||||
ind.Set(reflect.Indirect(reflect.ValueOf(sc)))
|
||||
}
|
||||
}
|
||||
|
||||
case reflect.Ptr:
|
||||
if value == nil {
|
||||
ind.Set(reflect.Zero(ind.Type()))
|
||||
break
|
||||
}
|
||||
ind.Set(reflect.New(ind.Type().Elem()))
|
||||
o.setFieldValue(reflect.Indirect(ind), value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -458,6 +458,14 @@ func TestNullDataTypes(t *testing.T) {
|
||||
throwFail(t, AssertIs((*d.TimePtr).UTC().Format(testTime), timePtr.UTC().Format(testTime)))
|
||||
throwFail(t, AssertIs((*d.DatePtr).UTC().Format(testDate), datePtr.UTC().Format(testDate)))
|
||||
throwFail(t, AssertIs((*d.DateTimePtr).UTC().Format(testDateTime), dateTimePtr.UTC().Format(testDateTime)))
|
||||
|
||||
// test support for pointer fields using RawSeter.QueryRows()
|
||||
var dnList []*DataNull
|
||||
Q := dDbBaser.TableQuote()
|
||||
num, err = dORM.Raw(fmt.Sprintf("SELECT * FROM %sdata_null%s where id=?", Q, Q), 3).QueryRows(&dnList)
|
||||
throwFailNow(t, err)
|
||||
equal := reflect.DeepEqual(*dnList[0], d)
|
||||
throwFailNow(t, AssertIs(equal, true))
|
||||
}
|
||||
|
||||
func TestDataCustomTypes(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user