Blog do projektu Open Source JavaHotel

piątek, 28 grudnia 2012

DB2, ODBC/CLI, Linux, 64bit

I run into very nasty problem related to setting up ODBC connection using 64 bit Linux client. The problem is described here but is easy to ignore it (as I did).
While defining DB2 driver in /etc/odbcinst.ini file use:

# Driver for DN2
Description     = ODBC for DB2
Driver64        = /home/opt/ibm/db2/V10.1/lib64/
Pay attention to letter o after libdb2. If you omit it the whole stuff seemingly works with only one exception: NULL values in the result set are not recognized. is "CLI DB2 driver" and "" is "ODBC driver". The main difference is handling SQLLEN data type. On 64 bit Linux DB2/CLI uses 32 bit but unixODBC and use 64 bit. It mean that the code below does not work as expected if compiled with ODBC header and run against return 32 bit -1 but ODBC code compares it with -1 64 bit. :

        SQLRETURN ret;
        SQLLEN cbData = 0;

        ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), nTargetType, buffer.GetBuffer(), buffer.GetRemaining(), &cbData);

        if (cbData == SQL_NULL_DATA) {
 // expected NULL value

Brak komentarzy:

Publikowanie komentarza