I was trying to grab which odbc driver versions are installed in a linux server by listing the drivers in the /etc/odbcinst.ini
file and I noticed that the DriverODBCVer
paramater is not available for the Postgres driver
[PostgreSQL]
Description =ODBC for PostgreSQL
Driver=/usr/lib/psqlodbcw.so
Setup=/usr/lib/libodbcpsqlS.so
Driver64=/usr/lib64/psqlodbcw.so
Setup64=/usr/lib64/libodbcpsqlS.so
FileUsage=1
I already tried using lsmod and also fetch from /proc/modules with no success. I basically tried all the topics related to this other topic
Is there any way to fetch the postgres ODBC driver that was installed in a linux server and currently configured to be used as a default? To give some context, One of processes (that returns the driver information) is giving us a different version from the one that should be installed.
Thanks!
CodePudding user response:
It seems like the only way is to write a C program that calls the SQLGetInfo
function with SQL_DRIVER_VER
as InfoType
.
Here is a minimal program that works for me:
#include <sql.h>
#include <sqlext.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv)
{
SQLHENV henv;
SQLHDBC hdbc;
char version[25];
SQLSMALLINT version_size;
(void) SQLAllocHandle(SQL_HANDLE_ENV,
SQL_NULL_HANDLE,
&henv);
(void) SQLSetEnvAttr(henv,
SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC3,
0);
(void) SQLAllocHandle(SQL_HANDLE_DBC,
henv,
&hdbc);
(void) SQLGetInfo(hdbc,
SQL_DRIVER_VER,
&version,
25,
&version_size);
write(1, version, strlen(version));
write(1, "\n", 1);
return 0;
}
Here is how I build and run it:
> gcc -Wall -o odbcversion -Wl,-rpath,/usr/pgsql-14/lib odbcversion.c /usr/pgsql-14/lib/psqlodbc.so
> ./odbcversion
13.02.0000