Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Can't get UNICODE support with QODBC and IBM DB2

    General and Desktop
    3
    9
    184
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pedrogkb
      pedrogkb last edited by pedrogkb

      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;
      }
      
      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        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.

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 4
        • G
          Gerd last edited by

          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

          1 Reply Last reply Reply Quote 1
          • pedrogkb
            pedrogkb last edited by

            Qt 5.14.2 and IBM DB2 11.5

            1 Reply Last reply Reply Quote 0
            • G
              Gerd last edited by

              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...

              1 Reply Last reply Reply Quote 1
              • pedrogkb
                pedrogkb last edited by

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

                1 Reply Last reply Reply Quote 0
                • G
                  Gerd last edited by

                  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...

                  1 Reply Last reply Reply Quote 1
                  • pedrogkb
                    pedrogkb last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • pedrogkb
                      pedrogkb last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post