Skip to content

Instantly share code, notes, and snippets.

@osak
Created April 14, 2013 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osak/5382860 to your computer and use it in GitHub Desktop.
Save osak/5382860 to your computer and use it in GitHub Desktop.
import Database.HDBC
import Database.HDBC.MySQL as MySQL
-- Test code based on a stackoverflow question:
-- http://stackoverflow.com/questions/15982588/hdbc-odbc-mysql-query-only-fails-when-compiled
-- Original code is here:
-- http://pastebin.com/9vrStfs7
-- Test Environments:
-- CPU: Core i7-3770
-- OS: Linux 3.8.5
-- GHC: 7.6.2
-- HDBC-mysql: 0.6.6.1
connectDatabase :: IO MySQL.Connection
connectDatabase = connectMySQL defaultMySQLConnectInfo
{ mysqlHost = "127.0.0.1" , mysqlUser = "osak", mysqlPassword = "test", mysqlDatabase = "test", mysqlPort = 3306, mysqlUnixSocket = "/var/run/mysqld/mysqld.sock" }
main = do
nativeconn <- connectDatabase
test6 nativeconn
putShow = putStrLn . show
-- runghc: prints "0"
-- ghc -O2: SqlError
test1 conn = run conn "CREATE OR REPLACE VIEW user_usergroup_map AS SELECT * FROM users" [] >>= putShow
-- runghc: prints nothing
-- ghc -O2: prints nothing
test2 conn = seq (run conn "CREATE OR REPLACE VIEW user_usergroup_map AS SELECT * FROM users" [] >>= putShow) (return ())
-- runghc: prints "0"
-- ghc -O2: SqlError
test3 conn = do
rows <- run conn "CREATE OR REPLACE VIEW user_usergroup_map AS SELECT * FROM users" []
putShow rows
-- runghc: nothing happens
-- ghc -O2: nothing happens
test4 conn = do
run conn "INSERT INTO users (name) VALUES ('osak')" []
-- runghc: 1 entry inserted
-- ghc -O2: raises SqlError but insert was succeeded
test5 conn = do
run conn "INSERT INTO users (name) VALUES ('osak')" []
commit conn
-- runghc: nothing happens
-- ghc -O2: nothing happens
test6 conn = do
(run conn "INSERT INTO users (name) VALUES ('osak')" []) `seq` (commit conn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment