From af4464ce585434015ab51bcf21ab9da8a7a448f4 Mon Sep 17 00:00:00 2001 From: zav8 Date: Fri, 1 Feb 2019 15:27:10 +0800 Subject: [PATCH] add support for pointer fields of structs to method QueryRows() --- orm/orm_raw.go | 8 ++++++++ orm/orm_test.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/orm/orm_raw.go b/orm/orm_raw.go index 27651fe4..3325a7ea 100644 --- a/orm/orm_raw.go +++ b/orm/orm_raw.go @@ -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) } } diff --git a/orm/orm_test.go b/orm/orm_test.go index 4f499a7c..0e2bf732 100644 --- a/orm/orm_test.go +++ b/orm/orm_test.go @@ -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) {