-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi Statements support #2 #339
Conversation
currently trying to add the test for the multiple batch update query.
i tried to do an multiple update queries and run a select statement to check if the result is correct.
here user.Get(sess) basically does:
so it leave me very confused as to why the vanilla mysql driver having problem performing this.
test code shortened for less verbose |
The problem is not the select statements, it is the original multiple update which leaves unread "OK" responses in the buffer. You see the "Commands out of sync" error when the driver attempts to reuse a buffer with an additional response that hasn't been read remaining in it. This is a flaw in the Go SQL interface, not the driver, as it has no ability to handle the multiple responses. There are some hacks available but they all boil down to reading and discarding additional responses which is fine if the user keeps the usage to only one needed result set but can't work it doing multiple query results. |
There's another effort for this in #338... Pro: we get a lot of tickets for stored procedures and gain an often used feature. The hardest problem I see here is that we can only sensibly return the result for the very first or very last executed query (by documented policy) - and that will probably include fun queries like setting delimiters to something else than |
Actually, this might not work for Exec calls because the driver loses control over the result set so can never get to the next one to discard it. I think these fixes/hacks, including #338, will only work for Query and QueryRow calls. For Stored Procedures (my problem which first got me involved in this issue) the very last result set is always an OK, so you would have to use the first one. |
u have actually deviate a little from the database/sql/driver when you start implementing the interpolateParams feature. that wasnt the intended design for the driver. The solution in #338 is mandating the multiStatements flag to be added to the packets.go. Whereas my solution is adding it to an optional dsn setting that the dev can switch on after understanding what he can or cannot do with it. I am currently only addressing the Exec command. Not Query calls, nor stored procedure. |
discard additional OK response after Multi Statement Exec Calls
Thanks for the heads up, i have incorporated some changes from #338 for the discarding the extra results return after the multi statement calls. |
This way is very good. |
the only change u need is to add '&multiStatements=true' to ur dsn string |
@badoet maybe we deviated with interpolateParams - but if so, we did it in a way that's never confusing and fully enables it as a feature. Whatever we do with stored procedures, they won't work in a database/sql/driver compatible way without some unavailable features and strange corner cases requiring deeper knowledge of MySQL internals. |
The built-in function & stored procedures in SQL, which also has a switch to choose? |
hmm. again, my use case is very specific in a way. please stop deviating my point to 'stored procedure'. again, it is not! |
Ok, I misunderstood. I'm automatically thinking of stored procedures when multi statement suport comes up because we get that request often enough... |
I'll try to add support for statements with multiple return values (e.g. stored procedures) based on lucalooz@9542bdd first. |
What's the status of this PR? I would also like to execute multiple statements (discarding the results is fine). |
this has been put on hold for so long that there r conflicts with master to resolve now :( |
Only took a couple minutes to merge: amacneil@73eacf5 |
👍 |
Damn, this PR would be a life-savior ! |
It will be merged within the next days :) |
New PR in #411 |
Add 'multiStatements' param to the dsn string.
multiStatements is for a batch fire and forget db operations.
this will help optimize the round trip.
in a transaction, multiple updates through goroutine seems to not run concurrently
Limitations:
n, _ := res.RowsAffected()
n will return 1 instead of the x number of rows updated in the batch query
tested with gocraft/dbr works as intended