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. QSqlQuery::bindValue() : Is possible to bound values to multiple locations?
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery::bindValue() : Is possible to bound values to multiple locations?

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 3 Posters 2.2k 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.
  • C Online
    C Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 2 Dec 2019, 14:26 last edited by
    #2

    It's still 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

    1 Reply Last reply
    2
    • P Offline
      P Offline
      PetrS82
      wrote on 2 Dec 2019, 14:56 last edited by
      #3

      I' sorry exactly this example ( INSERT INTO testtable (id, name, samename) VALUES (:id, :name, :name) ) works.
      But some exaples deos not work.

      1 Reply Last reply
      0
      • C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 2 Dec 2019, 15:01 last edited by
        #4

        @PetrS82 said in QSqlQuery::bindValue() : Is possible to bound values to multiple locations?:

        But some exaples deos not work.

        Which example does not work? 'Some' is a little bit imprecise.

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

        P 1 Reply Last reply 3 Dec 2019, 14:41
        1
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 2 Dec 2019, 22:00 last edited by
          #5

          Hi,

          What SQL backend are you using ?
          Some have changed over time to implement that feature. IIRC, the SQLite driver recently was updated because the SQLite version used had that feature implemented.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply 3 Dec 2019, 14:29
          0
          • S SGaist
            2 Dec 2019, 22:00

            Hi,

            What SQL backend are you using ?
            Some have changed over time to implement that feature. IIRC, the SQLite driver recently was updated because the SQLite version used had that feature implemented.

            P Offline
            P Offline
            PetrS82
            wrote on 3 Dec 2019, 14:29 last edited by
            #6

            Oracle 12.1.0

            1 Reply Last reply
            0
            • C Christian Ehrlicher
              2 Dec 2019, 15:01

              @PetrS82 said in QSqlQuery::bindValue() : Is possible to bound values to multiple locations?:

              But some exaples deos not work.

              Which example does not work? 'Some' is a little bit imprecise.

              P Offline
              P Offline
              PetrS82
              wrote on 3 Dec 2019, 14:41 last edited by PetrS82 12 Mar 2019, 14:48
              #7

              Hello,
              I made following table (using Oracle SQL Developer):
              create table testtable (KEY VARCHAR(255), VALUE VARCHAR(255), ID VARCHAR(255));

              In C++ I have folloving code:

              QSqlQuery query(db);
              
              query.prepare("declare "
                          "x NUMBER; "
                          "begin "
                          "insert into testtable(KEY, VALUE, ID) "
                          "values ('INIT_TEST', :INIT_ID, :INIT_ID); "
                          "insert INTO testtable(ID, KEY, VALUE) "
                          "select :RESULT_ID, 'TEST_INIT_ID', VALUE "
                          "from testtable "
                          "where ID = :INIT_ID; "
                          "end; ");
              
              
              query.bindValue(":INIT_ID", 1000);
              query.bindValue(":RESULT_ID", 2000);
              
              
              if (query.exec()) {
                  cout << "query.exec: OK" << endl;
              } else {
                  cout << "query.exec: error " << query.lastError().text().toStdString() << endl;
              }
              

              The expected result is:

               ID     |       KEY         |  VALUE
              1000    |   INIT_TEST       |  1000
              2000    |  TEST_INIT_ID     |  1000
              

              But the real result is:

               ID     |        KEY       |  VALUE
              1000    |   INIT_TEST      |  1000
              1000    |  TEST_INIT_ID    |  1000
              

              Both IDs are 1000 (and console output is "query.exec: OK").
              Note that if I run this statement in SQL Developer, the result is as expected.

              1 Reply Last reply
              0
              • C Online
                C Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 3 Dec 2019, 14:49 last edited by
                #8

                As @SGaist and I already said - don't use it. It may work (with the Qt Sqlite driver) but obviously not with the Qt ODBC driver (which you seem to use, but did not yet told us).

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

                P 3 Replies Last reply 3 Dec 2019, 14:55
                0
                • C Christian Ehrlicher
                  3 Dec 2019, 14:49

                  As @SGaist and I already said - don't use it. It may work (with the Qt Sqlite driver) but obviously not with the Qt ODBC driver (which you seem to use, but did not yet told us).

                  P Offline
                  P Offline
                  PetrS82
                  wrote on 3 Dec 2019, 14:55 last edited by
                  #9
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • C Christian Ehrlicher
                    3 Dec 2019, 14:49

                    As @SGaist and I already said - don't use it. It may work (with the Qt Sqlite driver) but obviously not with the Qt ODBC driver (which you seem to use, but did not yet told us).

                    P Offline
                    P Offline
                    PetrS82
                    wrote on 3 Dec 2019, 15:07 last edited by
                    #10

                    @Christian-Ehrlicher QOCI

                    1 Reply Last reply
                    0
                    • C Christian Ehrlicher
                      3 Dec 2019, 14:49

                      As @SGaist and I already said - don't use it. It may work (with the Qt Sqlite driver) but obviously not with the Qt ODBC driver (which you seem to use, but did not yet told us).

                      P Offline
                      P Offline
                      PetrS82
                      wrote on 3 Dec 2019, 15:17 last edited by
                      #11

                      @Christian-Ehrlicher
                      Is QOCI what you asked me? I don't know more. Here is one line (edited) form config.xml file we use for connection

                      connection user="user_foo" password="password_foo" host="localhost" port="port_number" typ="QOCI" name="DATABASE_FOO" sid="ORCL" db_name="ORCL"

                      1 Reply Last reply
                      0
                      • C Online
                        C Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 3 Dec 2019, 16:37 last edited by
                        #12

                        QOCI is even older - it has not been touched since Qt4 times so if it did not work with Qt4 it will not with Qt5.

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

                        P 1 Reply Last reply 4 Dec 2019, 11:52
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 3 Dec 2019, 20:36 last edited by
                          #13

                          IIRC, you can check if the driver provided that feature.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • C Christian Ehrlicher
                            3 Dec 2019, 16:37

                            QOCI is even older - it has not been touched since Qt4 times so if it did not work with Qt4 it will not with Qt5.

                            P Offline
                            P Offline
                            PetrS82
                            wrote on 4 Dec 2019, 11:52 last edited by
                            #14

                            @Christian-Ehrlicher

                            cout << "NamedPlaceholders: " << db.driver()->hasFeature(QSqlDriver::NamedPlaceholders) << endl;
                            cout << "PositionalPlaceholders: " << db.driver()->hasFeature(QSqlDriver::PositionalPlaceholders) << endl;

                            OUTPUT:
                            NamedPlaceholders: 1
                            PositionalPlaceholders: 0

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 4 Dec 2019, 23:00 last edited by
                              #15

                              @PetrS82 said in QSqlQuery::bindValue() : Is possible to bound values to multiple locations?:

                              query.prepare("declare "
                              "x NUMBER; "
                              "begin "
                              "insert into testtable(KEY, VALUE, ID) "
                              "values ('INIT_TEST', :INIT_ID, :INIT_ID); "
                              "insert INTO testtable(ID, KEY, VALUE) "
                              "select :RESULT_ID, 'TEST_INIT_ID', VALUE "
                              "from testtable "
                              "where ID = :INIT_ID; "
                              "end; ");

                              Isn't that set of queries invalid ?
                              Your second insert is missing the values part and your select clause explicitly asks to show the value of :RESULT_ID first and then the content of the other two columns. Which makes the output you show even more surprising.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              1

                              11/15

                              3 Dec 2019, 15:17

                              • Login

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