Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. To build ODBC plugin I need the whole source code?
Forum Updated to NodeBB v4.3 + New Features

To build ODBC plugin I need the whole source code?

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
14 Posts 3 Posters 1.5k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by Mark81
    #1

    I'm quite confused about the building of the ODBC plugin (to connect to a MySQL database).
    Here I read:

    The ODBC driver is build by default

    Instead, here it seems I need to build it.

    I have already installed unixODBC. Now, if I need to build the ODBC plugin the docs say:

    cd $QTDIR/qtbase/src/plugins/sqldrivers
    

    Dumb question: do I need to download the whole Qt source repository? Or is it possible to find and download only the sqldrivers sub-module?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mark81 said in To build ODBC plugin I need the whole source code?:

      do I need to download the whole Qt source repository?

      No, just QtBase. Also not the repository but the source code matching your Qt version.

      Or is it possible to find and download only the sqldrivers sub-module?

      No, this is not possible

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @Mark81 said in To build ODBC plugin I need the whole source code?:

        do I need to download the whole Qt source repository?

        No, just QtBase. Also not the repository but the source code matching your Qt version.

        Or is it possible to find and download only the sqldrivers sub-module?

        No, this is not possible

        M Offline
        M Offline
        Mark81
        wrote on last edited by Mark81
        #3

        @Christian-Ehrlicher I did what you suggested, but when I issued the following commands (link updated to Qt6) I get errors:

        qt-cmake --build .
        qt-cmake --install
        

        Actually, I had to type:

        cmake --build .
        cmake --install .
        

        But I'm pretty sure I can't be right and the official docs wrong. Anyway, the build was completed successfully.
        I cannot find libodbcHDB.so in the output directory. I only find libqsqlodbc.so.

        Christian EhrlicherC 1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          Hi, you're sure you want the odbc driver file libodbcHDB.so?
          I think that file is for SAP HANA and not for MySQL.

          1 Reply Last reply
          1
          • M Mark81

            @Christian-Ehrlicher I did what you suggested, but when I issued the following commands (link updated to Qt6) I get errors:

            qt-cmake --build .
            qt-cmake --install
            

            Actually, I had to type:

            cmake --build .
            cmake --install .
            

            But I'm pretty sure I can't be right and the official docs wrong. Anyway, the build was completed successfully.
            I cannot find libodbcHDB.so in the output directory. I only find libqsqlodbc.so.

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Mark81 said in To build ODBC plugin I need the whole source code?:

            I cannot find libodbcHDB.so in the output directory. I only find libqsqlodbc.so.

            Qt does not build a plugin named libodbcHDB.so - it only creates the libqsqlodbc.so for ODBC access. Don't know why you think you need the other one though.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            M 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @Mark81 said in To build ODBC plugin I need the whole source code?:

              I cannot find libodbcHDB.so in the output directory. I only find libqsqlodbc.so.

              Qt does not build a plugin named libodbcHDB.so - it only creates the libqsqlodbc.so for ODBC access. Don't know why you think you need the other one though.

              M Offline
              M Offline
              Mark81
              wrote on last edited by Mark81
              #6

              @Christian-Ehrlicher I was my fault then. I saw this code in the link above. I assumed the example was for ODBC.
              Anyway, I was able to compile this test application:

              #include <QCoreApplication>
              #include <QSqlDatabase>
              #include <QSqlError>
              #include <QDebug>
              
              int main(int argc, char *argv[])
              {
                  QCoreApplication a(argc, argv);
              
                  QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                  QString connectString = QStringLiteral(
                      "DRIVER=/home/mark/Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlodbc.so;"
                      "SERVERNODE=192.168.1.28:3306;"
                      "UID=admin;"
                      "PWD=<password>;"
                      "SCROLLABLERESULT=true");
                  db.setDatabaseName(connectString);
              
                  qDebug() << db.open();
                  qDebug() << db.lastError().text();
              
                  return a.exec();
              }
              

              but it does not connect:

              false
              "[unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed QODBC: Unable to connect"

              Using mysql I confirm it works:

              mysql -h 192.168.1.28 -u admin -p
              

              Maybe I still got it wrong?

              Christian EhrlicherC 1 Reply Last reply
              0
              • M Mark81

                @Christian-Ehrlicher I was my fault then. I saw this code in the link above. I assumed the example was for ODBC.
                Anyway, I was able to compile this test application:

                #include <QCoreApplication>
                #include <QSqlDatabase>
                #include <QSqlError>
                #include <QDebug>
                
                int main(int argc, char *argv[])
                {
                    QCoreApplication a(argc, argv);
                
                    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                    QString connectString = QStringLiteral(
                        "DRIVER=/home/mark/Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlodbc.so;"
                        "SERVERNODE=192.168.1.28:3306;"
                        "UID=admin;"
                        "PWD=<password>;"
                        "SCROLLABLERESULT=true");
                    db.setDatabaseName(connectString);
                
                    qDebug() << db.open();
                    qDebug() << db.lastError().text();
                
                    return a.exec();
                }
                

                but it does not connect:

                false
                "[unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed QODBC: Unable to connect"

                Using mysql I confirm it works:

                mysql -h 192.168.1.28 -u admin -p
                

                Maybe I still got it wrong?

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Mark81 said in To build ODBC plugin I need the whole source code?:

                "DRIVER=/home/mark/Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlodbc.so;"

                This is wrong. You have to pass the correct odbc driver name for your MySQL odbc connection.
                But why do you want to use the ODBC plugin to access a mysql database? Wouldn't it be better to directly use the Qt MySQL plugin then?

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                M 1 Reply Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  @Mark81 said in To build ODBC plugin I need the whole source code?:

                  "DRIVER=/home/mark/Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlodbc.so;"

                  This is wrong. You have to pass the correct odbc driver name for your MySQL odbc connection.
                  But why do you want to use the ODBC plugin to access a mysql database? Wouldn't it be better to directly use the Qt MySQL plugin then?

                  M Offline
                  M Offline
                  Mark81
                  wrote on last edited by Mark81
                  #8

                  @Christian-Ehrlicher I apologize, I'm not an expert of database. This morning the database developer said me: "please connect to our MySql database using an ODBC connection on address x and port y".

                  You have to pass the correct odbc driver name for your MySQL odbc connection

                  I'm not sure to understand. Which are the possible names? I mean, in the plugins/sqldrivers/ I see:

                  libqsqlite.so libqsqlodbc.so

                  But I'm sure they are not using SQLite.
                  I'm going to try with QtMySQL, but - be patient - where does the ODBC connection go then?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mark81
                    wrote on last edited by
                    #9

                    It seems I was able to connect!

                    #include <QCoreApplication>
                    #include <QSqlDatabase>
                    #include <QSqlError>
                    #include <QDebug>

                    int main(int argc, char *argv[])
                    {
                    QCoreApplication a(argc, argv);

                    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                    db.setHostName("192.168.1.28");
                    db.setPort(3306);
                    db.setDatabaseName("<db>");
                    db.setUserName("admin");
                    db.setPassword("<password>");
                    
                    qDebug() << db.open();
                    qDebug() << db.lastError().text();
                    
                    return a.exec();
                    

                    }

                    Still I don't understand why he asked my for ODBC while here I didn't use it...

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Mark81 said in To build ODBC plugin I need the whole source code?:

                      Still I don't understand why he asked my for ODBC while here I didn't use it...

                      You did use it

                      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      M 1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @Mark81 said in To build ODBC plugin I need the whole source code?:

                        Still I don't understand why he asked my for ODBC while here I didn't use it...

                        You did use it

                        QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");

                        M Offline
                        M Offline
                        Mark81
                        wrote on last edited by
                        #11

                        @Christian-Ehrlicher Sorry, perhaps I explained it wrong.
                        The code above that begins with:

                        QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                        

                        does not connect, while the code that begins with:

                        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                        

                        does connect.
                        I understand you can say: "well, if it works why still questioning?". I'm afraid about the request of the developer to connect using ODBC. I don't know in detail how it works under the hood, so I'm not sure if I fit the constraints.

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Because, as I said above you're passing a wrong driver string to the ODBC driver.

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          M 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            Because, as I said above you're passing a wrong driver string to the ODBC driver.

                            M Offline
                            M Offline
                            Mark81
                            wrote on last edited by Mark81
                            #13

                            @Christian-Ehrlicher I will be happy if you would help me to understand how to select the correct string.

                            Christian EhrlicherC 1 Reply Last reply
                            0
                            • M Mark81

                              @Christian-Ehrlicher I will be happy if you would help me to understand how to select the correct string.

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @Mark81 I don't know the correct ODBC string for you and would need to google around. But it's the same as you want to open an odbc connection on windows and at least not a path to a qt plugin.

                              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
                              2

                              • Login

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