Product: unixODBC
Affected versions: unixODBC-2.3.1 and some earlier versions (2.2.14 was also tested and found to be affected)
OS: Solaris10 32 and 64-bit (tested SPARC only). The same code works fine on Linux, but breaks on Solaris.
Problem description:
unixODBC fails to work correctly with PostgreSQL drivers (tested versions are psqlodbc-09.00.0310 and psqlodbc-09.01.0100).
The error received is:
[IM005][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_DBC failed
[ISQL]ERROR: Could not SQLConnect
I have applied the following fix to DriverManager/SQLConnect.c to work around the bug:
--- unixODBC-2.3.1/DriverManager/SQLConnect.c 2011-11-25 02:35:21.000000000 +1100
+++ /var/tmp/unixODBC-2.3.1/DriverManager/SQLConnect.c 2012-03-02 14:37:07.954098000 +1100
@@ -1217,9 +1217,9 @@
* with glib 2.0.6
*/
- if ( connection -> functions[ i ].func &&
- (void*)connection -> functions[ i ].func ==
- (void*)connection -> functions[ i ].dm_func )
+ if ( ( connection -> functions[ i ].func &&
+ (void*)connection -> functions[ i ].func ==
+ (void*)connection -> functions[ i ].dm_func ) || ( !i && !strcmp(driver_name, "PostgreSQL")) )
{
connection -> functions[ i ].func = NULL;
}
After applying the fix and recompiling everything works as normal.
So, to provide a bit of an explanation:
on the first run through the loop there (i=0) connection -> functions[ i ].func needs to be set to NULL, otherwise it just doesn't work.
Please note that I do not claim any understanding of the code, and therefore the provided workaround, although appearing to work, may not be the best one. This is what I did (after much debugging with gdb in both Solaris and Linux and comparing the execution paths) to get the drivers to work on Solaris 10.