Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't get UNICODE support with QODBC and IBM DB2

Can't get UNICODE support with QODBC and IBM DB2

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 574 Views
  • 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.
  • pedrogkbP Offline
    pedrogkbP Offline
    pedrogkb
    wrote on last edited by pedrogkb
    #1

    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
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4
      • G Offline
        G Offline
        Gerd
        wrote on last edited by
        #3

        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
        1
        • pedrogkbP Offline
          pedrogkbP Offline
          pedrogkb
          wrote on last edited by
          #4

          Qt 5.14.2 and IBM DB2 11.5

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gerd
            wrote on last edited by
            #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...

            1 Reply Last reply
            1
            • pedrogkbP Offline
              pedrogkbP Offline
              pedrogkb
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Gerd
                wrote on last edited by
                #7

                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
                1
                • pedrogkbP Offline
                  pedrogkbP Offline
                  pedrogkb
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • pedrogkbP Offline
                    pedrogkbP Offline
                    pedrogkb
                    wrote on last edited by
                    #9

                    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
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved