database/sql mysql question

148 views
Skip to first unread message

Sander van Harmelen

unread,
Mar 23, 2015, 7:03:16 AM3/23/15
to golang-nuts
Not 100% sure if this is actually MySQL related, but I tested this with both MySQL drivers (found here https://github.com/golang/go/wiki/SQLDrivers) and get the same results for both of them. But when testing with the SQLite driver I do not have this same issue…

The thing I encounter is that while I’m in a transaction I cannot execute a new statement if I still have a rows object open. This this expected? Or can I tweak something to “fix” this?

Working example (no transaction used): http://play.golang.org/p/eWYzrP55SX
Failing example (with transaction): http://play.golang.org/p/cAUXbtOtpb

The errors I get from the drivers are “bad connection” (go-sql-driver) and "reply is not completely read” (ziutek).

Thanks,

Sander
 

Tamás Gulácsi

unread,
Mar 23, 2015, 4:27:22 PM3/23/15
to golan...@googlegroups.com
You have to use another connection for the other transaction, if you don't "finish" the cursor.
 

Sander van Harmelen

unread,
Mar 23, 2015, 4:37:07 PM3/23/15
to Tamás Gulácsi, golang-nuts
OK… So this is expected behaviour?

I now fixed it by first looping through all the rows and filling the data in a slice with structs. Then when I’m done looping through all the rows, I start another loop through the newly created slice with structs. It fixes my issue, but feels a little strange/wrong doing it like this.

Sander
 

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

Gulácsi Tamás

unread,
Mar 23, 2015, 4:48:15 PM3/23/15
to Sander van Harmelen, golang-nuts
AFAIK this is a "common" problem for database clients, or more specifically, the wire format they use.
For example Oracle does not have this problem (can use multiple cursors in parallel), but has other problems (no pure-Go client, abuse of SELECT statement (can return value, which could be modified later, needs the connection remain opened)...).

Sander van Harmelen

unread,
Mar 23, 2015, 5:23:22 PM3/23/15
to Gulácsi Tamás, golang-nuts
Check… I guess that was all I needed to hear :)

Thx,

Sander
 
Reply all
Reply to author
Forward
0 new messages