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 回答
- 0 關注
- 1544 瀏覽
添加回答
舉報
0/150
提交
取消