petek, 07. maj 2010

Compile DB2 plugin for Qt on Linux

Steps:
- get Qt from Nokia's page
- install it
- run configure like this:
./configure -plugin-sql-db2 -v -I /opt/ibm/db2/V9.7/include -L /opt/ibm/db2/V9.7/lib64/
make
make install (if you want to install it)


- this should compile DB2 plugin for Qt. Now you can use this installation or copy generated Qt db2 plugin (libsqldb2.so) to /usr/lib/qt4/plugins/sqldrivers

Access DB2 via ODBC on Linux

This is how to install ODBC on Linux (Kubuntu 10.04) and access it.
Steps:
- install DB2 (I always install everything)
- install unixODBC
- edit $HOME/.odbc.ini :
[DB_NAME]
Description = Connection to DB_NAME
Driver=$HOME/sqllib/lib/libdb2.so

- run db2ca and add DB_NAME (don't forget to add ODBC)
- now you can use it on Qt for example like this:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DB_NAME");
db.setUserName("DB_USER");
db.setPassword("DB_PASS");
db.open();
QSqlError error = db.lastError();
qDebug() << "db error = " << error;

QSqlQuery query = db.exec("SELECT 1 FROM SYSIBM.SYSDUMMY1");
while (query.next() == true) {
qDebug() << query.value(0).toString();
}