The simplest possible command-line ODBC client with SQL capabilities

If you have been struggling to find a simple command-line utility to test an ODBC connection and issue SQL commands like me… you’ll appreciate the fact that iodbctest, the sample application from the open-source iODBC (Independent Open DataBase Connectivity) implementation can actually be compiled and run under Windows.
It’s somehow funny that to test ODBC (a Windows API), one has to resort to an utility written to reimplement said API on other OSs.

Anyhow, here is what I did:

  1. download the latest stable source package for iODBC (at the time of writing v3.52.7)
  2. edit the samples/iodbctest.c file and:
    • remove the reference to iodbcext.h
    • include windows.h before sql.h
    • replace SQL_APPLICATION_NAME with 1051L
  3. compile and link using Visual Studio 2008 Express SP1 with the command: cl iodbctest.c odbc32.lib

Here is the modified source, license file and binary (to use it, you will need to install the Microsoft Visual C++ 2008 SP1 Redistributable Package (x86)).

Sample usage:

iodbctest_win "DSN=persistency;UID=libpf"
SQL> select * from catalog;