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. Query ":placeholder" does not work, but "?" does.
Forum Updated to NodeBB v4.3 + New Features

Query ":placeholder" does not work, but "?" does.

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

    i am trying to get stuff from my ui into a databse. so first i do a check if the entry already exists.

    1. if it exists i'll do an UPDATE SET WHERE clause.

    2. If not i'll do an INSERT INTO VALUES clause.

    in both of these cases, the last part (WHERE / VALUES) a :placeholder does not work.

    so here the 2 cases with both examples and how i tried them. with the one working and the other one not working.

    1:
    //(with ?)
    q.prepare("UPDATE my_table SET column1 = :val1 WHERE column2 = ?");
    q.bindValue(":val1", ui->my_line_edit->text());
    q.bindValue(1, ui->my_line_edit_2->text());
    q.exec();
    //WORKS

    //(with :placeholder)
    q.prepare("UPDATE my_table SET column1 = :val1 WHERE column2 = :val2");
    q.bindValue(":val1", ui->my_line_edit_1->text());
    q.bindValue(":val2", ui->my_line_edit_2->text());
    q.exec();
    //DOES NOT WORKS

    2:
    //(with ?)
    q.prepare("INSERT INTO my_table (column1) VALUES (?)");
    q.bindValue(0, ui->my_line_edit->text());
    q.exec();
    //WORKS

    //(with :placeholder)
    q.prepare("INSERT INTO my_table (column1) VALUES (:val)");
    q.bindValue(":val", ui->my_line_edit->text());
    q.exec();
    //DOES NOT WORK

    I hope i made the point clear.

    KroMignonK 1 Reply Last reply
    0
    • Q qtnoob420

      @KroMignon
      Desktop Qt 5.12.10 MingGW 64-Bit.

      I hope i got it this time :D

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #7

      @qtnoob420 said in Query ":placeholder" does not work, but "?" does.:

      I hope i got it this time :D

      Yes, that's correct.
      I think you problem is link to this ticket QTBUG-48471.
      It seems that PostgreSQL do not support prepare statements.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      Q 1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Which version of Qt are you using ?
        Which database backend ?

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

        Q 1 Reply Last reply
        0
        • Q qtnoob420

          i am trying to get stuff from my ui into a databse. so first i do a check if the entry already exists.

          1. if it exists i'll do an UPDATE SET WHERE clause.

          2. If not i'll do an INSERT INTO VALUES clause.

          in both of these cases, the last part (WHERE / VALUES) a :placeholder does not work.

          so here the 2 cases with both examples and how i tried them. with the one working and the other one not working.

          1:
          //(with ?)
          q.prepare("UPDATE my_table SET column1 = :val1 WHERE column2 = ?");
          q.bindValue(":val1", ui->my_line_edit->text());
          q.bindValue(1, ui->my_line_edit_2->text());
          q.exec();
          //WORKS

          //(with :placeholder)
          q.prepare("UPDATE my_table SET column1 = :val1 WHERE column2 = :val2");
          q.bindValue(":val1", ui->my_line_edit_1->text());
          q.bindValue(":val2", ui->my_line_edit_2->text());
          q.exec();
          //DOES NOT WORKS

          2:
          //(with ?)
          q.prepare("INSERT INTO my_table (column1) VALUES (?)");
          q.bindValue(0, ui->my_line_edit->text());
          q.exec();
          //WORKS

          //(with :placeholder)
          q.prepare("INSERT INTO my_table (column1) VALUES (:val)");
          q.bindValue(":val", ui->my_line_edit->text());
          q.exec();
          //DOES NOT WORK

          I hope i made the point clear.

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by KroMignon
          #3

          @qtnoob420 said in Query ":placeholder" does not work, but "?" does.:

          in both of these cases, the last part (WHERE / VALUES) a :placeholder does not work.

          to complete @SGaist questions: did you check q.prepare() returned value? If returning false than the query could not be prepared (cf documentation)

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Which version of Qt are you using ?
            Which database backend ?

            Q Offline
            Q Offline
            qtnoob420
            wrote on last edited by
            #4

            @SGaist
            QT Creator 4.13.1 (Community)

            PostgreSQL 9.5.25

            KroMignonK 1 Reply Last reply
            0
            • Q qtnoob420

              @SGaist
              QT Creator 4.13.1 (Community)

              PostgreSQL 9.5.25

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by KroMignon
              #5

              @qtnoob420 said in Query ":placeholder" does not work, but "?" does.:

              QT Creator 4.13.1 (Community)

              This is your IDE, but why Qt Kit you are using to build your application (cf. Tools/Options/Kits)?

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              Q 1 Reply Last reply
              0
              • KroMignonK KroMignon

                @qtnoob420 said in Query ":placeholder" does not work, but "?" does.:

                QT Creator 4.13.1 (Community)

                This is your IDE, but why Qt Kit you are using to build your application (cf. Tools/Options/Kits)?

                Q Offline
                Q Offline
                qtnoob420
                wrote on last edited by
                #6

                @KroMignon
                Desktop Qt 5.12.10 MingGW 64-Bit.

                I hope i got it this time :D

                KroMignonK 1 Reply Last reply
                0
                • Q qtnoob420

                  @KroMignon
                  Desktop Qt 5.12.10 MingGW 64-Bit.

                  I hope i got it this time :D

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by
                  #7

                  @qtnoob420 said in Query ":placeholder" does not work, but "?" does.:

                  I hope i got it this time :D

                  Yes, that's correct.
                  I think you problem is link to this ticket QTBUG-48471.
                  It seems that PostgreSQL do not support prepare statements.

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  Q 1 Reply Last reply
                  1
                  • KroMignonK KroMignon

                    @qtnoob420 said in Query ":placeholder" does not work, but "?" does.:

                    I hope i got it this time :D

                    Yes, that's correct.
                    I think you problem is link to this ticket QTBUG-48471.
                    It seems that PostgreSQL do not support prepare statements.

                    Q Offline
                    Q Offline
                    qtnoob420
                    wrote on last edited by qtnoob420
                    #8

                    @KroMignon as soon as i use my example with the :placeholder i get a syntax error returned from my query. but there is no syntax fault. as i said in my post, i just switched the ":placeholder" with a "?" and the it works fine again.

                    i suppose there is nothing i can do about it...

                    KroMignonK 1 Reply Last reply
                    0
                    • Q qtnoob420

                      @KroMignon as soon as i use my example with the :placeholder i get a syntax error returned from my query. but there is no syntax fault. as i said in my post, i just switched the ":placeholder" with a "?" and the it works fine again.

                      i suppose there is nothing i can do about it...

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by
                      #9

                      @qtnoob420 said in Query ":placeholder" does not work, but "?" does.:

                      i suppose there is nothing i can do about it...

                      As you can see, it is a limitation of PostgreSQL itself.

                      if(!q.prepare("UPDATE my_table SET column1 = :val1 WHERE column2 = :val2"))
                      {
                         qDebug() << "Prepare statement error:" << q.lastError().text();
                      }
                      

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      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