Introduction
Welcome to a short tutorial on ODBC programming. The goal of this tutorial is to introduce a C-Programmer to ODBC programming. During this tutorial we will code a simple program which connects to a database via ODBC and reads some data. There won't be any information on how to program ODBC Drivers or about unixODBC internals. Configuration won't be covered too. The program developed throughout this tutorial was originally coded under WinNT and later ported without any adjustments to Linux and unixODBC. This is how compatibility should work :)

The information given within this tutorial are brief at best. Please take it as a pointer where and how to start.


Requirements   I assume that you have
 
  • a system with unixODBC installed and with at least one working datasource configured.
  • the include files installed under /usr/include/odbc
  • a compiler installed and that you know how to use it ;)
Compiling   If gcc is installed type:
  gcc odbc.c -o odbc -lodbc
which will result in an executable named "odbc".
Database   Our database will have a single table:
 
tkeyuser
iduser sequence
dtname char(40)
dtmaxSize Integer

Our datasource will be named "web" and access is granted to the user "christa" with no password.