pgsql-odbc and iodbc (on OSX, at least)

From: Matt Lilley <matt(dot)lilley(at)securitease(dot)com>
To: pgsql-odbc(at)postgresql(dot)org
Subject: pgsql-odbc and iodbc (on OSX, at least)
Date: 2013-07-02 17:21:33
Message-ID: 51D30C1D.4080501@securitease.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-odbc

Hi,

I've been chasing down a confusing problem with pgsql-odbc and iodbc.
I've downloaded the latest version from git, configured with
--with-iodbc, compiled, and tried running this simple test program with
surprising results:

#include <sql.h>
#include <sqlext.h>

int main(int argc, char** argv)
{
SQLHENV henv;
SQLHDBC hdbc;
SQLCHAR connection_out[1025];
SQLSMALLINT connection_out_len;
SQLAllocEnv(&henv);
SQLAllocConnect(henv, &hdbc);
printf("Connect: %d\n", SQLDriverConnect(hdbc, NULL, DRIVER_STRING,
SQL_NTS, connection_out, 1024, &connection_out_len, SQL_DRIVER_NOPROMPT));
printf("Status: %d\n", SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, 0));
return 0;
}

I get Connect: 0, Status -2. (I should say this is also true of the
prebuilt binaries for OSX last time I tried them). Time for some
digging. pgsql-odbc does not implement SQLSetConnectOption, so I
expected iodbc's call to dlsym(..., "SQLSetConnectOption[W]") to return
NULL. It doesn't. Digging deeper, I realised that this is defined in
iodbc, and because iodbc-config --libs returns "-L/usr/lib -liodbc
-liodbcinst", psqlodbc[w].so is linked to libiodbc.x.dylib. This
explains which function it's finding: the driver manager is getting its
/own/ SQLSetConnectOption, and thinking it's the driver's one. When it
then calls the function, predictably the result is that the handle is
not recognised, and the call is rejected. (Yes, I know
SQLSetConnectOption is deprecated and has been for a long time now. This
sample code above is really a test case from a much larger application
which I don't control the source for.)

I edited the Makefile and removed the -liodbc, relinked, and presto -
everything worked. I don't know what the right answer is here: Is this
the fault of iodbc for returning -liodbc in --libs? (I'm not entirely
sure what --libs is intended for. Clearly not database *drivers* if it's
going to produce this logic!) or is this the fault of pgsql-odbc for not
doing something else? It's trivial enough to patch around by judicious
use of sed, but I see that you don't use sed anywhere else in the
autoconf files. Rather than reach into my personal toolbox and apply a
band-aid, I thought I'd better just point out the problem to the list in
the hope I can it fixed properly, and save someone else the same
head-scratching I went though.

While I have your attention, and discussing deprecated things, in
configure.ac I see
AM_CONFIG_HEADER([config.h])
which I had to replace with
AC_CONFIG_HEADERS([config.h])
before autotools would let me bootstrap. Is it possible to change this
as well?

Thanks,
Matt

--
_____________________________________________
Matt Lilley
Software Engineer
SecuritEase

Tel: +64 4 912-2100
Fax: +64 4 912-2101
E-mail: matt(dot)lilley(at)securitease(dot)com
Web: http://www.securitease.com
_____________________________________________

This e-mail has passed our content security scan.
It is covered by the confidentiality clauses at http://www.securitease.com/content_and_confidentiality

Browse pgsql-odbc by date

  From Date Subject
Next Message Maziar Navahan 2013-07-04 09:13:02 Check out my profile on LinkedIn
Previous Message onur gulsevgi 2013-06-29 05:50:43 configure: error: unixODBC library "odbcinst" not found while trying to compile odbc