hdbc-mysql
hdbc-mysql copied to clipboard
Statement won't be finished after all rows are read
Even though the document of fetchRow says "Will automatically call finish when the last row is read.", it doesn't finish the statement after it reads all rows. Actually, it finishes a statement when I try to read the next row of the last row. This causes an error when I use a statement in a transaction.
For example, this code throws an exception.
c <- connectMySQL ....
r <- withTransaction c $ c -> do
s <- prepare c "SELECT 1 + 1"
execute s []
fetchRow s
*** Exception: SqlError {seState = "", seNativeError = 2014, seErrorMsg = "Commands out of sync; you can't run this command now"}
The same error occurs when I call commit explicitly. Something like:
s <- prepare c "SELECT 1 + 1"
execute s []
r <- fetchRow s
commit c
When I call fetchRow one more time, or call finish explicitly, it works fine.
I had a similar problem. I was creating a connection, then passing it around thorough various functions, all part of one big long transaction, using "execute" and "quickQuery" mainly. Sometimes the transaction would complete, sometimes it would just hang forever, sometimes it would give me a random sqlException, and I even got a few segfaults and a core dump! The randomness made me think it had to do with either threading or garbage collection or maybe the RTS signalling problems.
I was at the end of my tether -- I know I was passing around a single connection, and (even though I wasn't using threads), wrapping the connection in an MVar didn't help. I put withRTSSignalsBlocked every which where, in all combinations. No good. That left garbage collection -- maybe my statements weren't being finalized properly, and were getting randomly garbage collected and exploding?
I added an explicit call to "finish" when I was done with each prepared statement, and now it works just fine. Something up here...
I'm afraid I'm unlikely to get to this any time soon, as I don't use HDBC any more. Your best bet is to try to fix it, and issue a pull request if you get something working.
I'll maybe have a go at it... Will indeed issue a pull request if I get it. Are you still using haskell and databases? If so, what are you using instead? (just curious) Thanks very much for your work on HDBC/mysql -- aside from this (resolved) issue, it's worked great for me, and been quick and easy to deploy, and a pleasure to use. =)
I faced similar issue in my tests. A lot of unfinished statements caused segmentation fault, so I had to finish them manually everywhere. Does anyone maintain this project for now?
@boris-stepanov I am the current maintainer.