cols, err := rows.Columns() // Remember to check err afterwards
vals := make([]interface{}, len(cols))for i, _ := range cols {
vals[i] = new(sql.RawBytes)
}for rows.Next() {
err = rows.Scan(vals...)
// Now you can check each element of vals for nil-ness,
// and you can use type introspection and type assertions
// to fetch the column into a typed variable.
}官方原文链接官方的Demo是这样写的,最下面留了3行注释:Now you can check each element of vals for nil-ness, and you can use type introspection and type assertions to fetch the column into a typed variable.请问这个use type introspection and type assertions to fetch the column into a typed variable到底要怎么实现?查了诸多资料都没有找到答案。网上大部分说的都是(string)value强转,可能这些说法都有些年代了,我现在这样写是不行的,会报错。
1 回答
- 1 回答
- 0 关注
- 1519 浏览
添加回答
举报
0/150
提交
取消