11 Oct 2012
Edit

Return to posts

Haskell ODBC MySQL connection issues

In a recent project I encountered the following intermittent bug: when performing MySQL queries using the HDBC-ODBC package I would sometimes receive the following error:


SqlError {seState = "[\"08S01\"]", seNativeError = -1, seErrorMsg = "execute execute: [\"2013: [MySQL][ODBC 5.1 Driver][mysqld-5.5.24-0ubuntu0.12.04.1]Lost connection to MySQL server during query\"]"}

The connection to the server isn’t being lost in this case, but the GHC runtime system is interfering with the MySQL connection system.

To solve this issue, the withRTSSignalsBlocked function must be imported from the HDBC-MySQL package, and used when calling any database access function:


import Database.HDBC

import Database.HDBC.ODBC

import Database.HDBC.MySQL(withRTSSignalsBlocked)

conn <- withRTSSignalsBlocked $ connectODBC "DSN=test"

-- Set a query here

let query = "SELECT page_id FROM page;"

dataset <- withRTSSignalsBlocked $ quickQuery conn query []

withRTSSignalsBlocked $ disconnect conn

This issue started appearing for me when I upgraded to Ubuntu 12.04.