hdbc-mysql icon indicating copy to clipboard operation
hdbc-mysql copied to clipboard

Statement won't be finished after all rows are read

Open snakamura opened this issue 13 years ago • 5 comments

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.

snakamura avatar Dec 02 '11 08:12 snakamura

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...

interzoneboy avatar Aug 17 '12 01:08 interzoneboy

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.

bos avatar Aug 25 '12 05:08 bos

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. =)

interzoneboy avatar Aug 25 '12 06:08 interzoneboy

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 avatar Nov 11 '19 19:11 boris-stepanov

@boris-stepanov I am the current maintainer.

ryantm avatar Nov 16 '19 14:11 ryantm