Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. MySQL query
Forum Updated to NodeBB v4.3 + New Features

MySQL query

Scheduled Pinned Locked Moved Solved C++ Gurus
11 Posts 4 Posters 1.8k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    A select query that returns nothing is likely what you want to check.

    What exactly is your issue with that ?

    One tip, if you only want to check that it exists, no need to query the content of the whole table, only the field you are interested in is enough.

    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
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #3

      In addition to what @SGaist suggested you can make the database table use a unique key on the data fields being inserted. That way if you try to insert the same data more than once the transaction will fail. At least that is the strategy I do in PostgreSQL. I assume unique keys are supported in mySQL.

      1 Reply Last reply
      0
      • XmodptX Offline
        XmodptX Offline
        Xmodpt
        wrote on last edited by Xmodpt
        #4

        hello @SGaist and @Kent-Dorfman

        I am realy sorry but i have pasted the wrong query....
        the correct one is

        candidate_query := SELECT domain FROM candidates WHERE domain = :d;
        

        It seems that i haven't explain my self correctly

        the intent is not to "input" data into the table but read from data from it.

        in a nut shell....

        Camera reads plate -> check if plate exists in DB -> if exists... shows a Warning Message that includes the detected plate + custom text... if not... keep reading.

        NOTE: the data in the database is a user input process via a dashboard manualy.

        Hope'd i was able to clarify my questions....

        regards
        NP

        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #5

          then simply write a query looking for that license number. If the number of rows returned equals zero then it was not found. pretty simple...

          1 Reply Last reply
          0
          • XmodptX Offline
            XmodptX Offline
            Xmodpt
            wrote on last edited by
            #6

            the question is how do i put it in C++ and in my UI form to echo the output

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #7
              QSqlQuery query;
              query.prepare("SELECT domain FROM candidates WHERE domain = :d");
              query.bindValue(":d", domain);
              if(!query.exec())
              qDebug() << "Unable to execute query";
              if(query.next()){
              qDebug() << "The domain is already in the database";
              }
              

              shows a Warning Message

              https://doc.qt.io/qt-5/qmessagebox.html#warning

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              XmodptX 1 Reply Last reply
              2
              • XmodptX Offline
                XmodptX Offline
                Xmodpt
                wrote on last edited by Xmodpt
                #8

                @VRonin

                Thank you for your help. I will test it tomorrow and I'll let you know.

                Ps- in order the get the warning to work on my UI all I need is to change from qdebug to ui->

                Thank you
                Np

                1 Reply Last reply
                0
                • VRoninV VRonin
                  QSqlQuery query;
                  query.prepare("SELECT domain FROM candidates WHERE domain = :d");
                  query.bindValue(":d", domain);
                  if(!query.exec())
                  qDebug() << "Unable to execute query";
                  if(query.next()){
                  qDebug() << "The domain is already in the database";
                  }
                  

                  shows a Warning Message

                  https://doc.qt.io/qt-5/qmessagebox.html#warning

                  XmodptX Offline
                  XmodptX Offline
                  Xmodpt
                  wrote on last edited by Xmodpt
                  #9

                  @VRonin

                  Hello m8

                  It worked like a charm... thank you very much for the tip.

                  Let me ask you guys a tip:

                  I have made some changes but what i need to get the a custom output in the QMessageBox. something like

                  "Warning: XX@@ZZ (domain VAR) plate is blacklisted!"

                  is there a way to output my (domain) var in the QMessageBox ?

                  My current code:

                  
                      QSqlQuery query;
                      query.prepare("SELECT domain FROM candidates WHERE domain = :d");
                      query.bindValue(":d", domain);
                      if(!query.exec())
                      qDebug() << "Unable to execute query";
                      if(query.next()){
                      qDebug() << "The domain is already in the database";
                          QMessageBox msgBox;
                          QPixmap myIcon(":/images/danger.png");
                          msgBox.setIconPixmap(myIcon);
                          msgBox.setText("PLATE IS BLACKLISTED.");
                          msgBox.exec();
                  

                  Also i have tried using a UI Form but i was unable to print my "domain" value output

                  //////// UI FORM - msgbox.ui///////

                        MsgBox msgbox;
                         msgbox.setModal(true);
                         msgbox.exec();
                  

                  ///////////////////////////////////////////////////////////////////////////////////

                  Kind Regards
                  Xmodpt

                  1 Reply Last reply
                  1
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #10

                    msgBox.setText(QStringLiteral("%1 PLATE IS BLACKLISTED.").arg(domain));

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    XmodptX 1 Reply Last reply
                    1
                    • VRoninV VRonin

                      msgBox.setText(QStringLiteral("%1 PLATE IS BLACKLISTED.").arg(domain));

                      XmodptX Offline
                      XmodptX Offline
                      Xmodpt
                      wrote on last edited by
                      #11

                      @VRonin

                      Hello m8

                      Thankyou verry much for all your help.
                      ALL is working like it should thanks to you.

                      Until next time
                      Xmodpt

                      1 Reply Last reply
                      1

                      • Login

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