Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can't get UNICODE support with QODBC and IBM DB2



  • I'm building an application to view some data in the database of my company's ERP, which is a DB2 database. The ERP app uses ODBC for the connection, so I'm using QODBC, together with the IBM ODBC Driver. However I cannot get Unicode characters from the DB. I've tried using QTextCodec, but I only get different crazy symbols with different codecs. I've been looking to use the QDB2 driver, but I need to compile that, which is impossible apparently, the closest I get is the qmake config giving a bunch of errors from the DB2 headers and libs. I'm not very familiar with qmake or QODBC, so any help/suggestion is greatly appreciated. Here's my connectionString (I've added the last append line and the setConnectOptions() to try to fix the issue, but nothing changes with or without those):

    QString connecString = "Driver={"+db2Driver+"};";
    connecString.append("HOSTNAME="+db2IP+";SERVICENAME="+db2Port+";");
    connecString.append("DATABASE="+db2Name+";");
    connecString.append("Uid="+db2User+";");
    connecString.append("Pwd="+db2Password+";");
    connecString.append("PROTOCOL="+db2Protocol+";");
    connecString.append("DISABLEUNICODE=0;TXNISOLATION=1");
    db2.setConnectOptions("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3");
    db2.setDatabaseName(connecString);
    if(db2.open()){
        return 0;
    }else{
         QMessageBox::critical( nullptr, "Erro!", "Erro ao estabelecer a conexão:\n" + db2.lastError().text(), QMessageBox::Ok);
         qDebug() << "DB2 ERROR: " << db2.lastError().text();
         return 1;
    }
    

  • Qt Champions 2019

    I don't see what Qt can do here - when the odbc driver does not return that it supports unicode, Qt can't use it. See https://code.woboq.org/qt5/qtbase/src/plugins/sqldrivers/odbc/qsql_odbc.cpp.html#_ZN18QODBCDriverPrivate12checkUnicodeEv for the needed checks.



  • Hi
    had the same problem some time ago and could only resolve it by changing the sources of the qt sql-drivers.
    Didnt test it with the current versions of qt/db2/odbc, so at least you should tell us about the versions u are using.

    gerd



  • Qt 5.14.2 and IBM DB2 11.5



  • just tried to start my yesterday installed db2 v11.5, nothing happend. no usefull errormessage, no help for that.
    never seen such a crappy product...



  • Exactly, I hate IBM software because of this kind of stuff, no helpful support, terrible website...



  • trying different ways to install db2 11.5, but nothing worked. so idid some tests on an older machine with db2 9.x using the qt db2driver and everything works fine. so maybe we can help you building the qt db2 driver, normally an easy task.
    all you need are the header and lib files in your sqllib dir and then it should work as described in the docs:

      cd %QTDIR%\qtbase\src\plugins\sqldrivers
      qmake -- "DB2_PREFIX=<DB2 home>/sqllib"
      nmake sub-db2
    

    if that dont work you should show some errormessages...



  • Thank you for your help, can you please send me the headers and libs for that version of DB2?



  • I finally managed to build the driver with IBM DB2 11.5 libs and headers, turns out I just needed to use the MSVC 2017 compiler.
    Full unicode support now.
    Had some problems with the compiler in the past, but works just fine now, compile times for my program are vastly better too.


Log in to reply