Rjdlee
Rjdlee

Reputation: 779

Retrieving Values From a Prepared Statement and Select Query in Go

I'm unsure how to retrieve values from a prepared statement since result only returns information about the transaction.

statement, err := txn.Prepare(`SELECT id, password FROM public.user WHERE email = $1`)
result, err = stmt.Exec(email, password, email)

I understand Query() and QueryRow() have the intended result, but from what I understand, they are unsafe. Any help on this is appreciated, thanks.

Upvotes: 3

Views: 2454

Answers (1)

OneOfOne
OneOfOne

Reputation: 99215

They are perfectly safe, you use it the same way, exec is really just for inserts:

stmt, err := txn.Prepare(`SELECT id, password FROM public.user WHERE email = $1`)
rows, err := stmt.Query(email)

Check: https://code.google.com/p/go-wiki/wiki/SQLInterface

Upvotes: 4

Related Questions