I mention about the below func of ```database/sql``` package and I'm using
golang 1.7.
func (db *DB) Query(query string, args ...interface{}) (*Rows, error) {...}
I'm using MySQL and handling query result like that code below, (there are
some omissions.)
sql := "SELECT field1, field2 FROM t_xxx WHERE flg=?"
//1-1) added args parameter
rows, err := ms.DB.Query(sql, 1)
values := make([]interface{}, 2)
scanArgs := make([]interface{}, 2)
for i := range values {
scanArgs[i] = &values[i]
}
err = rows.Scan(scanArgs...)
//1-2) I expect that type of field1 is int64
val := reflect.ValueOf(values[0])
//val.Kind()==reflect.Int64
//------------------
//Next check
//------------------
//2-1) no args parameter
rows1, err := ms.DB.Query(sql)
values2 := make([]interface{}, 2)
scanArgs2 := make([]interface{}, 2)
for i := range values2 {
scanArgs2[i] = &values2[i]
}
err = rows2.Scan(scanArgs2...)
//2-2) I expect that type of field1 is int64
val := reflect.ValueOf(values2[0])
//But, result was not int, it was byte. and it can be asseted as string.
//val.Kind()==reflect.Slice ([]uint8)
When adding args to Query func, result type is OK, but without it, result
type change into []byte.
Why, result type changed???
Thank you.
Harry
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.