I have 2 columns if table accounts
:
oid
and balance
By the next code I try to extract oid
then balance
:
// variable `id` comes from an another part
sqlstr := `SELECT * ` +
`FROM accounts ` +
`WHERE oid=` + id + `;`
q, err := db.Query(sqlstr)
if err != nil {
fmt.Println("Error: GetAccount
", err)
return Account{}, err
}
defer q.Close()
var _id string
var bal float64
q.Next()
q.Scan(&_id)
fmt.Println("_id ", _id)
q.Next()
q.Scan(&bal)
fmt.Println("bal ", bal)
After the first q.Next()
I expected to extract oid
and after the second to extract balance
.
But every time after the first q.Next()
and after the second I only get balance
.
I tried to change sqlstr
to the next:
sqlstr := `SELECT oid, balance ` +
`FROM accounts ` +
`WHERE oid=` + id + `;`
But I still cannot extract oid.