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. Whats the problem with this? if i enter wrong ID key error not showing up
Qt 6.11 is out! See what's new in the release blog

Whats the problem with this? if i enter wrong ID key error not showing up

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 3 Posters 16.4k Views 2 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.
  • the_T the_

    @Aquarius171

    Where do you execute the query after preparing it?

    A Offline
    A Offline
    Aquarius171
    wrote on last edited by
    #9

    @the_ What do you mean?

    the_T 1 Reply Last reply
    0
    • A Aquarius171

      @the_ What do you mean?

      the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #10

      @Aquarius171

      http://doc.qt.io/qt-5/qsqlquery.html#isActive

      As you can see in the docs, a query is only active while executing. So you always will get "Not active" in your code sample.

      And: did you have a look at the former link how to correctly use prepared statements?

      -- No support in PM --

      A 1 Reply Last reply
      0
      • the_T the_

        @Aquarius171

        http://doc.qt.io/qt-5/qsqlquery.html#isActive

        As you can see in the docs, a query is only active while executing. So you always will get "Not active" in your code sample.

        And: did you have a look at the former link how to correctly use prepared statements?

        A Offline
        A Offline
        Aquarius171
        wrote on last edited by
        #11

        @the_

        search = self.search.text()

            self.query = QSqlQuery()
            self.query.prepare("select * from incoming_mac_records where ID = '%s'"%str(search))
            self.query.addBindValue(search)
        

        if(not self.query.exec_()):
        print "Not active"
        if(self.query.next()):
        print "Active"

        how about this?

        the_T 1 Reply Last reply
        0
        • A Aquarius171

          @the_

          search = self.search.text()

              self.query = QSqlQuery()
              self.query.prepare("select * from incoming_mac_records where ID = '%s'"%str(search))
              self.query.addBindValue(search)
          

          if(not self.query.exec_()):
          print "Not active"
          if(self.query.next()):
          print "Active"

          how about this?

          the_T Offline
          the_T Offline
          the_
          wrote on last edited by
          #12

          @Aquarius171

          you did not read/understand how to use prepare correctly?

          
          self.query = QSqlQuery()
          self.query.prepare("select * from incoming_mac_records where ID=?")
          self.query.addBindValue(self.search.text())
          if not self.query.exec():
            print self.query.lastError()
          else:
            while self.query.next():
              #do whatever you need to do
          

          -- No support in PM --

          A 3 Replies Last reply
          1
          • the_T the_

            @Aquarius171

            you did not read/understand how to use prepare correctly?

            
            self.query = QSqlQuery()
            self.query.prepare("select * from incoming_mac_records where ID=?")
            self.query.addBindValue(self.search.text())
            if not self.query.exec():
              print self.query.lastError()
            else:
              while self.query.next():
                #do whatever you need to do
            
            A Offline
            A Offline
            Aquarius171
            wrote on last edited by
            #13

            @the_ why this is not showing when i enter wrong input

            if not self.query.exec(): #sysntax error so i make it like this self.query.exec_()
            print self.query.lastError()

            1 Reply Last reply
            0
            • the_T the_

              @Aquarius171

              you did not read/understand how to use prepare correctly?

              
              self.query = QSqlQuery()
              self.query.prepare("select * from incoming_mac_records where ID=?")
              self.query.addBindValue(self.search.text())
              if not self.query.exec():
                print self.query.lastError()
              else:
                while self.query.next():
                  #do whatever you need to do
              
              A Offline
              A Offline
              Aquarius171
              wrote on last edited by
              #14

              @the_ and i try to use .isActive() and same happens but not returning error message like print "record not found"

              1 Reply Last reply
              0
              • the_T the_

                @Aquarius171

                you did not read/understand how to use prepare correctly?

                
                self.query = QSqlQuery()
                self.query.prepare("select * from incoming_mac_records where ID=?")
                self.query.addBindValue(self.search.text())
                if not self.query.exec():
                  print self.query.lastError()
                else:
                  while self.query.next():
                    #do whatever you need to do
                
                A Offline
                A Offline
                Aquarius171
                wrote on last edited by
                #15

                @the_
                search = self.search.text()

                    self.query = QSqlQuery()
                    self.query.prepare("select * from incoming_mac_records where ID =?")
                    self.query.addBindValue(search)
                    
                    if not self.query.exec_():
                        print self.query.lastError()
                    else:
                        while self.query.next():
                

                if the ID key is active it show the print statement "active" but if not existing the self.query.lastError() not showing up

                jsulmJ 1 Reply Last reply
                0
                • A Aquarius171

                  @the_
                  search = self.search.text()

                      self.query = QSqlQuery()
                      self.query.prepare("select * from incoming_mac_records where ID =?")
                      self.query.addBindValue(search)
                      
                      if not self.query.exec_():
                          print self.query.lastError()
                      else:
                          while self.query.next():
                  

                  if the ID key is active it show the print statement "active" but if not existing the self.query.lastError() not showing up

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #16

                  @Aquarius171 I already told you two times that QSqlQuery::exec() does NOT fail if the id is not found! Do you actually read what others write?
                  exec() only fails if your query is invalid (wrong SQL syntax) or there is no database connection. If the id is not found exec() will not fail (this is now the third and last time I tell this, sorry, but you really should read answers) - it will execute successfully and the result will be an empty table. A SQL SELECT statement NEVER fails if it does not find anything, instead it returns an empty result.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  4
                  • jsulmJ jsulm

                    @Aquarius171 I already told you two times that QSqlQuery::exec() does NOT fail if the id is not found! Do you actually read what others write?
                    exec() only fails if your query is invalid (wrong SQL syntax) or there is no database connection. If the id is not found exec() will not fail (this is now the third and last time I tell this, sorry, but you really should read answers) - it will execute successfully and the result will be an empty table. A SQL SELECT statement NEVER fails if it does not find anything, instead it returns an empty result.

                    A Offline
                    A Offline
                    Aquarius171
                    wrote on last edited by
                    #17

                    @jsulm for that thank you! and sorry :) GodBless sir ^_^ Have a nice day

                    jsulmJ 1 Reply Last reply
                    0
                    • A Aquarius171

                      @jsulm for that thank you! and sorry :) GodBless sir ^_^ Have a nice day

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #18

                      @Aquarius171 No problem! It's just that it is sometimes annoying if you repeat the same several times but the questioner does not read or ignore your explanation :-)
                      One tip: if you only need to know whether the ID is used use
                      SELECT count(*) FROM incoming_mac_records WHERE ID =?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 2 Replies Last reply
                      1
                      • jsulmJ jsulm

                        @Aquarius171 No problem! It's just that it is sometimes annoying if you repeat the same several times but the questioner does not read or ignore your explanation :-)
                        One tip: if you only need to know whether the ID is used use
                        SELECT count(*) FROM incoming_mac_records WHERE ID =?

                        A Offline
                        A Offline
                        Aquarius171
                        wrote on last edited by
                        #19

                        @jsulm how do i display count?

                        1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Aquarius171 No problem! It's just that it is sometimes annoying if you repeat the same several times but the questioner does not read or ignore your explanation :-)
                          One tip: if you only need to know whether the ID is used use
                          SELECT count(*) FROM incoming_mac_records WHERE ID =?

                          A Offline
                          A Offline
                          Aquarius171
                          wrote on last edited by
                          #20

                          @jsulm how to use isNull( int )?

                          the_T jsulmJ 2 Replies Last reply
                          0
                          • A Aquarius171

                            @jsulm how to use isNull( int )?

                            the_T Offline
                            the_T Offline
                            the_
                            wrote on last edited by the_
                            #21

                            @Aquarius171

                            Again: you did not read and/or understand the PyQT QSqlQuery documentation??

                            -- No support in PM --

                            A 1 Reply Last reply
                            1
                            • A Aquarius171

                              @jsulm how to use isNull( int )?

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #22

                              @Aquarius171 If you're asking questions then please explain better!
                              Where do you want to display count?
                              Where do you want to use isNull() and for what data?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              A 1 Reply Last reply
                              0
                              • jsulmJ jsulm

                                @Aquarius171 If you're asking questions then please explain better!
                                Where do you want to display count?
                                Where do you want to use isNull() and for what data?

                                A Offline
                                A Offline
                                Aquarius171
                                wrote on last edited by
                                #23

                                @jsulm thank you already figure it out Thank you and sorry again sir ! :)

                                1 Reply Last reply
                                0
                                • the_T the_

                                  @Aquarius171

                                  Again: you did not read and/or understand the PyQT QSqlQuery documentation??

                                  A Offline
                                  A Offline
                                  Aquarius171
                                  wrote on last edited by
                                  #24

                                  @the_ i am reading it now haha sorry bro

                                  1 Reply Last reply
                                  0

                                  • Login

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