From 53b59d278d8a04833b143bc253951d61105d07a1 Mon Sep 17 00:00:00 2001 From: Carlos Nieto <jose.carlos@menteslibres.net> Date: Fri, 11 Apr 2014 18:57:57 -0500 Subject: [PATCH] Using []interface{} instead of []string for query arguments. --- util/sqlutil/main.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/util/sqlutil/main.go b/util/sqlutil/main.go index beac4c89..8da4bd76 100644 --- a/util/sqlutil/main.go +++ b/util/sqlutil/main.go @@ -44,7 +44,7 @@ type QueryChunks struct { Offset string Sort string Conditions string - Arguments []string + Arguments []interface{} } func (self *T) ColumnLike(s string) string { @@ -188,6 +188,9 @@ func (self *T) FetchRow(dst interface{}, rows *sql.Rows) error { next := rows.Next() if next == false { + if err = rows.Err(); err != nil { + return err + } return db.ErrNoMoreRows } @@ -249,10 +252,10 @@ func (self *T) FetchRows(dst interface{}, rows *sql.Rows) error { return nil } -func (self *T) FieldValues(item interface{}, convertFn func(interface{}) string) ([]string, []string, error) { +func (self *T) FieldValues(item interface{}, convertFn func(interface{}) interface{}) ([]string, []interface{}, error) { fields := []string{} - values := []string{} + values := []interface{}{} itemv := reflect.ValueOf(item) itemt := itemv.Type() @@ -262,7 +265,7 @@ func (self *T) FieldValues(item interface{}, convertFn func(interface{}) string) case reflect.Struct: nfields := itemv.NumField() - values = make([]string, 0, nfields) + values = make([]interface{}, 0, nfields) fields = make([]string, 0, nfields) for i := 0; i < nfields; i++ { @@ -313,7 +316,7 @@ func (self *T) FieldValues(item interface{}, convertFn func(interface{}) string) } case reflect.Map: nfields := itemv.Len() - values = make([]string, nfields) + values = make([]interface{}, nfields) fields = make([]string, nfields) mkeys := itemv.MapKeys() -- GitLab