Where are you calling Exec on the statement?

On Monday, August 28, 2017 at 3:52:54 PM UTC+2, Ain wrote:
>
> Hi
>
> Tested with 1.9 and got the same behaviour - first row is returned OK, the 
> second returns error.
>
> Does anyone use prepared select statements sucessfully? With which 
> DB/driver?
> I'm sure that if my code is silly someone would have pointed it out so I'm 
> wondering am I the only one trying to use prepared select statements...
>
>
> TIA
> ain
>
>
>
> On Thursday, August 17, 2017 at 12:03:47 AM UTC+3, Ain wrote:
>>
>> Hi
>>
>> I tried to use prepared statements and it works first time, but fails on 
>> second query. Ie code like
>>
>>     tx, err := db.Begin()
>>     if err != nil {
>>         log.Fatalf("Error starting tx: %v", err)
>>     }
>>     defer tx.Rollback()
>>     st, err := tx.Prepare("select foo from t where id=?")
>>     if err != nil {
>>         log.Fatalf("Error preparing stmnt: %v", err)
>>     }
>>     defer st.Close()
>>     var n int
>>     err = st.QueryRow(1).Scan(&n)
>>     if err != nil {
>>         log.Fatalf("Error selecting(1): %v", err)
>>     }
>>     fmt.Println("[1] =", n)
>>     err = st.QueryRow(2).Scan(&n)
>>     if err != nil {
>>         log.Fatalf("Error selecting(2): %v", err)
>>     }
>>     fmt.Println("[2] =", n)
>>
>> the first row value is printed OK but the second QueryRow fails with 
>> "Error op_response:0" message (this is with Firebird driver 
>> github.com/nakagami/firebirdsql). Both id's exist in the DB so single 
>> row is expected for both executions.
>> I also got error with "github.com/mattn/go-sqlite3" driver so I don't 
>> think this is a driver specific issue... either I use it the wrong way or 
>> there is a bug in the database/sql?
>>
>> go version go1.8.1 linux/amd64
>>
>> TIA
>> ain
>>
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to