Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QSqlQuery select statment
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery select statment

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
15 Posts 3 Posters 3.9k 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.
  • M Offline
    M Offline
    MrLibya
    wrote on 13 Oct 2016, 13:20 last edited by
    #6

    i also tried

            query.addBindValue(ui->Numberinput->text());
            query.addBindValue(ui->search_item->text());
    

    but the same

    R 1 Reply Last reply 13 Oct 2016, 13:40
    0
    • M MrLibya
      13 Oct 2016, 13:20

      i also tried

              query.addBindValue(ui->Numberinput->text());
              query.addBindValue(ui->search_item->text());
      

      but the same

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 13 Oct 2016, 13:40 last edited by
      #7

      @MrLibya
      this error is very unspecific and may also occur when the query itself is invalid.
      As i already stated, whats about the table name [main].[items]. Is this really correct?!

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      M 1 Reply Last reply 13 Oct 2016, 13:46
      0
      • R raven-worx
        13 Oct 2016, 13:40

        @MrLibya
        this error is very unspecific and may also occur when the query itself is invalid.
        As i already stated, whats about the table name [main].[items]. Is this really correct?!

        M Offline
        M Offline
        MrLibya
        wrote on 13 Oct 2016, 13:46 last edited by MrLibya
        #8

        @raven-worx yep , i've already used this method in another function and it's work very well

        void MainWindow::UpdateSearchItem(QStringList *List)
        {
            QSqlQuery query("SELECT * FROM [main].[items]");
            while (query.next())
                *List << query.value(1).toString();
        }
        
        1 Reply Last reply
        0
        • H Online
          H Online
          hskoglund
          wrote on 13 Oct 2016, 14:18 last edited by
          #9

          Hi, maybe the text substitution goes haywire, to see the resolved text, try:
          qDebug() << query.executedQuery();

          M 1 Reply Last reply 13 Oct 2016, 14:26
          1
          • H hskoglund
            13 Oct 2016, 14:18

            Hi, maybe the text substitution goes haywire, to see the resolved text, try:
            qDebug() << query.executedQuery();

            M Offline
            M Offline
            MrLibya
            wrote on 13 Oct 2016, 14:26 last edited by
            #10

            @hskoglund said in QSqlQuery select statment:

            qDebug() << query.executedQuery();

            i got

            "SELECT * FROM [main].[items] WHERE barcode = ? OR name = ? "
            
            H 1 Reply Last reply 13 Oct 2016, 17:32
            0
            • M MrLibya
              13 Oct 2016, 14:26

              @hskoglund said in QSqlQuery select statment:

              qDebug() << query.executedQuery();

              i got

              "SELECT * FROM [main].[items] WHERE barcode = ? OR name = ? "
              
              H Online
              H Online
              hskoglund
              wrote on 13 Oct 2016, 17:32 last edited by
              #11

              Indeed the text substitution seems borked, you could try instead doing the text substitution directly yourself, something like this:

              QSqlQuery query("SELECT * FROM [main].[items] WHERE barcode = '123' OR name = 'Smith'");
              
              M 1 Reply Last reply 13 Oct 2016, 19:51
              0
              • H hskoglund
                13 Oct 2016, 17:32

                Indeed the text substitution seems borked, you could try instead doing the text substitution directly yourself, something like this:

                QSqlQuery query("SELECT * FROM [main].[items] WHERE barcode = '123' OR name = 'Smith'");
                
                M Offline
                M Offline
                MrLibya
                wrote on 13 Oct 2016, 19:51 last edited by MrLibya
                #12

                @hskoglund that will not really helps , goes the barcode - name , the user will input from line edit , so dose this only not work on sqlite ? if i use mysql it will work ??

                1 Reply Last reply
                0
                • H Online
                  H Online
                  hskoglund
                  wrote on 13 Oct 2016, 20:05 last edited by
                  #13

                  Hi, you can build the select string something like this:

                  QString s = QString("SELECT * FROM [main].[items] WHERE barcode = '%1' OR name = '%2'").arg(ui->Numberinput->text()).arg(ui->search_item->text());
                  QSqlQuery query(s);
                  
                  M 1 Reply Last reply 13 Oct 2016, 20:38
                  2
                  • M Offline
                    M Offline
                    MrLibya
                    wrote on 13 Oct 2016, 20:36 last edited by
                    #14
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • H hskoglund
                      13 Oct 2016, 20:05

                      Hi, you can build the select string something like this:

                      QString s = QString("SELECT * FROM [main].[items] WHERE barcode = '%1' OR name = '%2'").arg(ui->Numberinput->text()).arg(ui->search_item->text());
                      QSqlQuery query(s);
                      
                      M Offline
                      M Offline
                      MrLibya
                      wrote on 13 Oct 2016, 20:38 last edited by
                      #15

                      @hskoglund thx it work :)

                      1 Reply Last reply
                      0

                      15/15

                      13 Oct 2016, 20:38

                      • Login

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