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. When QSqlQuery .exec function called?

When QSqlQuery .exec function called?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 398 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.
  • D Offline
    D Offline
    donkey007
    wrote on last edited by
    #1

    when i using under code

    [code example] :

    q.prepare();
    ~
    int tracking_id = 0;
    tracking_id ++;
    ~
    if(tracking_id == 2)
    {
    q.bindvalue(":ti", tracking_id);
    }
    ~
    if(q.exec())
    {
    emit send_data_to_center(data);
    }

    ======================================
    end of the running this code
    when i check the db
    i found tracking_id 0,1,2

    why this happend ?

    i thought .exec function only called when exist q.bindvalue ....
    please help me...

    JonBJ 1 Reply Last reply
    0
    • D donkey007

      when i using under code

      [code example] :

      q.prepare();
      ~
      int tracking_id = 0;
      tracking_id ++;
      ~
      if(tracking_id == 2)
      {
      q.bindvalue(":ti", tracking_id);
      }
      ~
      if(q.exec())
      {
      emit send_data_to_center(data);
      }

      ======================================
      end of the running this code
      when i check the db
      i found tracking_id 0,1,2

      why this happend ?

      i thought .exec function only called when exist q.bindvalue ....
      please help me...

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @donkey007

      When QSqlQuery .exec function called?

      It is called when it executes the if(q.exec()) in your code.

      i thought .exec function only called when exist q.bindvalue ....

      It is called when the line is hit. If you have only called q.bindvalue() when tracking_id == 2 then no value will be bound to :ti when tracking_id != 2, which will presumably cause your query not to work. We don't know because you don't show what your query is.

      1 Reply Last reply
      3
      • D Offline
        D Offline
        donkey007
        wrote on last edited by
        #3

        thanks for your comment :)
        it's my query :

        q.prepare("INSERT INTO "TABLE NAME" (id, tracking_id, check)"
        "VALURE (:id, :ti)" "ON CONFLICT (id) DO UPDATE SET tracking_id=:ti");

        so.. can you tell me what is problem is?

        i want to excute the .exec function only "tracking_id == 2"
        but now the .exec function also return true when tracking_id == 0 or 1

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @donkey007 said in When QSqlQuery .exec function called?:

          i want to excute the .exec function only "tracking_id == 2"

          Then change your code so it does what you want. Currently you always call exec().

          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
          1
          • D Offline
            D Offline
            donkey007
            wrote on last edited by
            #5

            now i know whats my problem is thank you sir!

            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