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. [SOLVED]Change a single value in a table (SQLITE update not work)

[SOLVED]Change a single value in a table (SQLITE update not work)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 4.0k 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.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by
    #1

    in a previus post I analyze these code:

    @ int p = 0, roid, p1 = 0;
    QSqlQuery qy(db);
    qy.prepare("SELECT id_pro1 FROM program WHERE pro1 = :pro1");
    qy.bindValue(":pro1", "ffff");
    qy.exec();
    qy.next();
    p = qy.record().toInt();
    ui->lcdNumber_2->display(p);
    qy.clear();
    @
    the above code, it is ok, and in these void work perfectly other two SELECT and one INSERT, but another .... not work ...

    @ q1y.prepare("UPDATE program SET id_pro1 = :id_pro1 WHERE pro1 = ffff"); /these code not work/
    q1y.bindValue(":id_pro1", roid);
    q1y.exec();
    q1y.next();
    p1 = qy.record().toInt();
    ui->lcdNumber->display(p1);
    q1y.clear();@

    If I canghe these snip into:

    @ q1y.prepare("INSERT program VALUES id_pro1 = :id_pro1 WHERE pro1 = ffff"); /these code not work/
    q1y.bindValue(":id_pro1", roid);
    q1y.exec();
    q1y.next();
    p1 = qy.record().toInt();
    ui->lcdNumber->display(p1);
    q1y.clear();@

    I see the same result: id_pro1 does not change.

    some ideas??

    bkt

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      is "ffff" a column in your sql table? or is it supposed to be a value? If it's a value shouldn't it look like 'value'?
      I may be wrong my SQL skills got a bit rusted over the last years ;)

      --- 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

      1 Reply Last reply
      0
      • gfxxG Offline
        gfxxG Offline
        gfxx
        wrote on last edited by
        #3

        no problem, ffff is a value .... the right code is (error by cntrlC/V from old post):

        @ q1y.prepare("INSERT program VALUES id_pro1 = :id_pro1 WHERE pro1 = ffff"); /these code not work/
        q1y.bindValue(":id_pro1", roid);
        q1y.exec();
        q1y.next();
        p1 = qy.value().toInt(); //// (error by cntrlC/V from old post)
        ui->lcdNumber->display(p1);
        q1y.clear();
        @

        And ffff is a value (actually is no a text but a int number)....

        bkt

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          could you please post the (effective) query which goes to the SQL server.

          --- 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

          1 Reply Last reply
          0
          • gfxxG Offline
            gfxxG Offline
            gfxx
            wrote on last edited by
            #5

            But is the correct way to write these update?
            8program=table, id_pro1 value to change, pro1=fff ->set correct row)

            @q1y.prepare("UPDATE program SET id_pro1 = :id_pro1 WHERE pro1 = ffff");@

            bkt

            1 Reply Last reply
            0
            • gfxxG Offline
              gfxxG Offline
              gfxx
              wrote on last edited by
              #6

              of course:

              @
              ui->lcdNumber->display(roid); //////////control & display roid int variable -> ok
              // ui->lcdNumber_2->display(p);

              QSqlQuery qram(db);
              qram.prepare("UPDATE valori SET (valore = :valore) WHERE (nome_valore = :nome_valore)");
                 qram.bindValue(":nome_valore", "id_ricetta1"); /*id_ricetta1 is an existing value in the column nome_valore*/
                 qram.bindValue(":valore", roid); /* I can not do the update of this cell*/
                 qrom.exec();
                 qDebug() << roid;
                 qram.clear();@
              

              bkt

              1 Reply Last reply
              0
              • gfxxG Offline
                gfxxG Offline
                gfxx
                wrote on last edited by
                #7

                @ QSqlQuery qram(db);
                qram.prepare("UPDATE valori SET valore=:valore WHERE nome_valore=:nome_valore");
                qram.bindValue(":nome_valore", "id_ricetta1");
                qram.bindValue(":valore", roid);
                qram.exec();
                qDebug() << roid;
                qram.lastError();
                qram.clear();@

                These work perfect!!!!

                bkt

                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