Skip to content
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

Statement won't be finished after all rows are read #6

Open
snakamura opened this issue Dec 2, 2011 · 5 comments
Open

Statement won't be finished after all rows are read #6

snakamura opened this issue Dec 2, 2011 · 5 comments

Comments

@snakamura
Copy link
Contributor

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.

@interzoneboy
Copy link

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

@bos
Copy link
Collaborator

bos commented Aug 25, 2012

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.

@interzoneboy
Copy link

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

@boris-stepanov
Copy link

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?

@ryantm
Copy link
Owner

ryantm commented Nov 16, 2019

@boris-stepanov I am the current maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants