Difference between revisions of "MetaHDBC Install"

From HaskellWiki
Jump to: navigation, search
m (Change of source repo)
m (Change of source repo)
Line 15: Line 15:
= Installing MetaHDBC =
= Installing MetaHDBC =
* darcs get http://autoforms.sourceforge.net/darcs/MetaHDBC/
* darcs get http://code.haskell.org/MetaHDBC/
* cd MetaHDBC
* cd MetaHDBC
* runhaskell Setup.?hs configure --prefix=$HOME --user
* runhaskell Setup.?hs configure --prefix=$HOME --user

Revision as of 15:58, 13 June 2008

This page is about installing MetaHDBC.


MetaHDBC depends upon HDBC and HDBC-ODBC. You can install HDBC as a normal cabalized package, but for HDBC-ODBC you should do:

The patch makes it possible to call SQLDescribeParam and removes the need to execute a SQL query before getting type information.

Installing MetaHDBC

  • darcs get http://code.haskell.org/MetaHDBC/
  • cd MetaHDBC
  • runhaskell Setup.?hs configure --prefix=$HOME --user
  • runhaskell Setup.?hs build
  • runhaskell Setup.?hs install

Running Test

After installation you can run some tests. They are located in the test directory. But beware, the tests drops tables, creates tables, and other data manipulation both at compile and run -time. So be sure that you do not accidentally destroy valuable data.

Before running the test you will need to install one or more databases. You can see the following section for some guidance.

In the file test/Test.hs you can decide which databases you want to test with.

In test/Metadata.hs you can set your data source names (DSN).

Database on Linux

To use MetaHDBC you will need a database. This section describes how to setup various databases for Linux.

You can use the popular open source databases PostgreSQL, MySQL and SQLite with MetaHDBC. They are all likely to be part of your Linux distribution. These databases in conjunction with MetaHDBC will provide you with SQL syntax check and it will give type inference for returned values. However, they will 'not' infer the types of positional parameters, as these databases do not support the ODBC function SQLDescribeParam properly.

For full type inference you can use DB2 or MS SQL Server. But I have not tested the latter and I would therefore encourage users of MS SQL Server to test MetaHDBC.


Using DB2 with MetaHDBC is attractive as DB2 supports the ODBC functions necessary for doing full type inference. The Express-C edition is also free of charge and Ubuntu makes DB2 Express-C available though their partner program.

DB2 Howto will help you install DB2. There are explanations for various flavors of Linux.

Before installing DB2 you should be given this fair warning. When I installed this .deb package, pointed to from the howto, the install script accidentally overwrote a file in /usr/include. This may or may not be true for the other types of packages pointed to from the howto.

The error is explained in more detail here.

Creating a database

To create a test database that MetaHDBC can use, do:

> su db2inst1 -l   # -l neccessary ?
> db2 create database <database name>
DB20000I  The CREATE DATABASE command completed successfully.

The database name must maximally be eight characters. Make a database called MHdbcDB2, if you want it to be usable from the MetaHDBC test programs.

UnixODBC setup

If you install the .deb package from above your /etc/odbcinst.ini should have added the following lines:

Description     = DB2 Driver
Driver          = /opt/ibm/db2exc/V9.5/lib32/libdb2.so
FileUsage       = 1
DontDLClose     = 1

and your /etc/odbc.ini should have this added:

Description     = Test DB2
Driver          = DB2
USER            = db2inst1
PASSWD          = <password of db2inst1 user>

The password is ibmdb2 if you have not changed it after installing DB2.

The UnixODBC.org site also has documentation for setting up ODBC for DB2.

PostgreSQL (Debian)

I have added the following section to /etc/odbcinst.ini:

Description     = PostgreSQL ODBC driver
Driver          = /usr/lib/odbc/psqlodbcw.so
Setup           = /usr/lib/odbc/libodbcpsqlS.so
Debug           = 0
CommLog         = 1
UsageCount      = 2

and I have added this to /etc/odbc.ini:

Description             = PostgreSQL ODBC
Driver                  = postgreodbc
Trace                   = No
TraceFile               =
Database                = MetaHDBC_DB
Servername              = localhost
UserName                = MetaHDBC
Password                = <password of MetaHDBC user>
Port                    = 5433
Protocol                = 8.3
ReadOnly                = No
RowVersioning           = No
ShowSystemTables        = No
ShowOidColumn           = No
FakeOidIndex            = No
ConnSettings            =

MySQL (Debian)

I have added the following section to /etc/odbcinst.ini:

DESCRIPTION          = MySQL Database connect
DRIVER               = /usr/lib/odbc/libmyodbc.so
Setup                = /usr/lib/odbc/libodbcmyS.so
FileUsage            = 1

and I have added this to /etc/odbc.ini:

DESCRIPTION = mysql driver 3.51
SERVER = localhost
PORT = 3306
Password = <password of MetaHDBC user>
Database = MetaHDBC
SOCKET = /var/run/mysqld/mysqld.sock

SQLite (Debian)

The SQLite database may be the easiest to use as it do not require a server. The database is just stored in a ordinary file. No need for passwords.

I have added the following section to /etc/odbcinst.ini:

Description           = SQLite ODBC Driver
Driver                = /usr/lib/odbc/libsqliteodbc.so
Setup                 = /usr/lib/odbc/libsqliteodbc.so
UsageCount            = 1

and I have added this to /etc/odbc.ini:

Description=My SQLite test database
Database=<path to database>
# optional lock timeout in milliseconds