[Haskell-cafe] Use MySQL from Haskell
Maciej Podgurski
maciej.podgurski at googlemail.com
Fri Jun 19 15:21:25 EDT 2009
Hi Björn,
thanks for your hint, I finally made HDBC-odbc and even hsql-mysql run.
Below is a step-by-step manual how to install both packages on windows
for people having the same troubles I had. I used GHC 6.8.3.
MySQL from HDBC-odbc
********************
1.) Install package time-1.1.2.4.
2.) Download package convertible-1.0.5. In convertible.cabal find the line
Build-Depends: ..., time>=1.1.2.4, ...
and replace it by
Build-Depends: ..., time>=1.1.2.4 && <1.1.3, ...
Now the installation shouldn't fail with a compilation error.
3.) Download package HDBC-2.1.1, modfiy HDBC.cabal in the same way as in
2.) and install the package.
4.) Install package HDBC-odbc-2.1.0.0.
5.) There still was one thing I didn't know that made my example fail
with an exception. You need to install a MySQL ODBC connector for
Windows (available from dev.mysql.com).
6) Now the following example should return a list of all table names in
the database:
import Database.HDBC
import Database.HDBC.ODBC
main :: IO ()
main = do
conn <- connectODBC "DRIVER={MySQL ODBC 5.1 Driver};
SERVER=my_server; DATABASE=my_database; UID=my_username;
PASSWORD=my_password"
qs <- quickQuery' conn "show tables" []
mapM_ (\[SqlByteString table] -> print table) qs
disconnect conn
(There's also a getTables function but it always returns an empty list
on my system, I don't know why).
MySQL from hsql-mysql
*********************
1.) Install package hsql-1.7.1.
2.) Download package hsql-mysql-1.7.1. In hsql-mysql.cabal find the line
include-dirs: Database/HSQL, /usr/include/mysql
and replace it by
include-dirs: Database/HSQL
Also find the line
extra-lib-dirs: /usr/lib/mysql
and remove it.
3.) Do a
runghc Setup configure --extra-include-dirs=<path_to_mysql>/include/
--extra-lib-dirs=<path_to_mysql>/lib/opt/
runghc Setup build
runghc Setup install
where <path_to_mysql> is the path to your MySQL server installation. I'm
using MySQL Server 5.1, so maybe you have to adjust the include or lib path.
4.) Now you should be able to compile:
import Database.HSQL
import Database.HSQL.MySQL
main :: IO ()
main = do
conn <- connect "my_server" "my_database" "my_username" "my_password"
ts <- tables conn
mapM_ print ts
disconnect conn
5.) Execute the main function. If you get an error like
Loading package hsql-mysql-1.7.1 ... can't load .so/.DLL for:
mysqlclient (addDLL: unknown error)
go to <path_to_mysql>/bin where a file "libmySQL.dll" should reside.
Copy this file to "mysqlclient.dll" and try executing the main function
again. Now you should get a list of all tables in the database.
Installing HDBC-mysql still failed due to a missing file "mysql_config"
which seems to be available only for linux systems.
Best wishes,
Maciej
W dniu 19.06.2009 09:31 Björn Peemöller pisze:
> Maciej Podgurski schrieb:
>> So I switched to HDBC-2.1.1 and got the next compile error:
>>
>> Building convertible-1.0.5...
>>
>> Data/Convertible/Instances/Num.hs:671:0:
>> warning: no newline at end of file
>> [...]
>> [5 of 8] Compiling Data.Convertible.Instances.C (
>> Data/Convertible/Instances/C.hs, dist\build/Data/C
>> onvertible/Instances/C.o )
>> [6 of 8] Compiling Data.Convertible.Instances.Time (
>> Data/Convertible/Instances/Time.hs, dist\build/
>> Data/Convertible/Instances/Time.o )
>>
>> Data/Convertible/Instances/Time.hs:64:0:
>> Duplicate instance declarations:
>> instance Typeable NominalDiffTime
>> -- Defined at Data/Convertible/Instances/Time.hs:(64,0)-(65,42)
>> instance Typeable NominalDiffTime
>> -- Defined in time-1.1.3:Data.Time.Clock.UTC
>>
>> Data/Convertible/Instances/Time.hs:67:0:
>> Duplicate instance declarations:
>> instance Typeable UTCTime
>> -- Defined at Data/Convertible/Instances/Time.hs:(67,0)-(68,34)
>> instance Typeable UTCTime
>> -- Defined in time-1.1.3:Data.Time.Clock.UTC
>
> Hi Maciej,
>
> this is quite easy to fix (although a little bit dirty). The problem is
> that time-1.1.3 now defines some Typeable instances which time-1.1.2.4
> did not and which are therefore defined in convertible, too. I don't
> know a general fix to the problem, but you can either
>
> - download the convertible package and comment out the two instance
> declarations as shown in the error message and then cabal install it
> - install from Hackage with additional constraint: cabal install
> convertible --constraint=time<1.1.3
>
> I hope this will help you get HDBC running.
>
> Cheers,
> Björn
>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list