web2py/web2py — pull request #537 by btreecat (2014-10-24 19:28:49+00:00)
Title: Add option of using offical ibm_db_dbi driver instead of ODBC driver for DB2 

In order to take advantage of this driver, you will also have to install the IBM Data Server Driver Package and configure a DSN in etiher the db2cli.ini or the db2dsdriver.cfg files.

And example db2dsdriver.cfg file would look like this:

After setting up the Data Server Driver Package and a DSN, you need to export the IBM_DB_HOME envar

export IBM_DB_HOME=/install/path/to/dsdriver/

Then you can install ibm_db from pypi

pip install ibm_db

Finally you need to set LD_LIBRARY_PATH envar to include the dsdriver/lib folder

export LD_LIBRARY_PATH=/install/path/to/dsdriver/lib:$LD_LIBRARY_PATH

You can now test the driver using Python like this:

import ibm_db_dbi
conn = ibm_db_dbi.connect('DB2', 'db2_user', 'db2_pass') #DB2 is the value of alias in db2dsdriver.cfg
cur = conn.cursor()
cur.execute("SELECT current date FROM sysibm.sysdummy1")
cur.fetchone()

The corresponding new connection string in web2py looks like this:

'db2:ibm_db_dbi://DSN=dsn;UID=user;PWD=pass'

And the updated one for ODBC connections:

'db2:pyodbc://driver=DB2;hostname=host;database=database;uid=user;pwd=password;port=port'

Similar changes could be made for the Informix adapter since the ibm_db_db/ibm_db_dbi driver supports it however I do not have the resources to test that database.