Question

I'm writing a web app using Snap 0.6 and the Snaplet-hdbc infrastructure. In the backend, I'm using HDBC-mysql to connect to MySQL. But when running the app, it gets a "Command out of sync, you can't run this command now" error from MySQL. I'am using withTransaction' for each query. After some googling, it seems that MySQL doesn't support multiple query. But how to avoid it using HDBC?

Was it helpful?

Solution

After some investigation, I found the solution. Don't use SELECT statement in withTransaction or with commit. And don't use query' for SELECT. In my opinion, HDBC-mysql is using the mysqlclient library, so you can't issue a new query when the data of last query is still unused or freed. Due to the laziness of haskell, if you run a SELECT in withTransaction, the data is unused until your code need it, so when the withTransaction function calls commit, it will result in the "Command out of sync" error. For query', maybe it returns the number of rows selected, but the data selected out is buffered by the mysqlclient library, so it's the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top