iODBC Driver Manager

iODBC is one of three popular ODBC driver managers available for Unix (the others being unixODBC, and Merant which is apparently the official licensed Microsoft ODBC driver manager ported to Unix).

First, build iODBC according to the documentation or install it via RPM, DEB or other package manager.

Now build FreeTDS using the --with-iodbc flag to specify where FreeTDS can find the include files from iODBC. For instance if iODBC's header files are in /opt/libiodbc/include use /opt/libiodbc. By default the location will be /usr/local.

$ ./configure --prefix=/usr/local/freetds --with-iodbc=/usr/local
$ gmake
$ su root
Password: 
$ gmake install

In this example the FreeTDS ODBC libraries will be installed in /usr/local/freetds/lib. We need to tell the driver manager where to find them. We do so by editing $HOME/.odbc.ini or /etc/odbc.ini. A sample odbc.ini file comes with FreeTDS in the samples directory.

Example 5-2. Sample odbc.ini File

;
;  odbc.ini
;
[ODBC Data Sources]
 JDBC = Sybase JDBC Server

[JDBC]
Driver          = /usr/local/freetds/lib/libtdsodbc.so
Description     = Sybase JDBC Server
Trace           = No
Servername      = JDBC
Database        = pubs2
UID             = guest
PWD             = sybase

[Default]
Driver          = /usr/local/freetds/lib/libtdsodbc.so
Here we specified that the JDBC entry from the FreeTDS interfaces file will show on a listing of DSNs (if this is Greek to you, please consult some ODBC documentation) and tell it to use the libtdsodbc library to connect with.

iODBC comes with a sample command line query program called odbctest that is located in the iodbc/samples directory. Using this program you can get a listing of DSNs, connect, and issue queries. It is often useful to compile a program such as this directly against the FreeTDS driver instead of using a driver manager. This makes it simpler to debug if something goes wrong. To do so, simply compile and install the ODBC driver with iODBC as normal, then compile and link the program directly:

$ make odbctest.o
$ gcc -g -o odbctest odbctest.o /usr/local/freetds/lib/libtdsodbc.a
The -g is important to keep the symbol tables for debugging purposes. Now you can run gdb or another debugger and set breakpoints on functions in the library without the driver manager getting in the way.

Note: When compiling directly to FreeTDS you still must use the driver manager's header files.