QSqlite ... problem with Update Statement ..
-
My code have an large use of QSlite and QSqlQuery for show and manage data .... I have an table with an only row, all integer item and use it for customize usage of app .... so need to update Item based an user preferences. I see my code running ok when cell of row was 5/6 ...but when become 20 stop to update ... but is possible to read without issue .... Maybe error is stupid but waste a lot of hour whitout find it .... my query:
QSqlQuery qryChState(Database); qryChState.prepare("UPDATE state_machine SET peo=:p1, nasri=:p2, ena_a=:p3, mag_p=:p4, ace=:p5, s_vi=:p6, lisys=:p7, any_d=:p8, esp_bus=:p9, a_zero=:p10, ilda=:p11, ctB=:p12, aoB=:p13, debug=:p14, x_Off_b:=p15, y_Off_b=:p16, f_Off_b=:p17, biB=:p18, biC=:p19, aOff=:p20 WHERE sysIdx = 0 "); //qryChState.bindValue(":p0", w0); qryChState.bindValue(":p1", w1); qryChState.bindValue(":p2", w2); qryChState.bindValue(":p3", w3); qryChState.bindValue(":p4", w4); qryChState.bindValue(":p5", w5); qryChState.bindValue(":p6", w6); qryChState.bindValue(":p7", w7); qryChState.bindValue(":p8", w8); qryChState.bindValue(":p9", w9); qryChState.bindValue(":p10", w10); qryChState.bindValue(":p11", w11); qryChState.bindValue(":p12", w12); qryChState.bindValue(":p13", w13); qryChState.bindValue(":p14", w14); qryChState.bindValue(":p15", w15); qryChState.bindValue(":p16", w16); qryChState.bindValue(":p17", w17); qryChState.bindValue(":p18", w18); qryChState.bindValue(":p19", w19); qryChState.bindValue(":p20", w20); qryChState.exec(); qDebug() << "error update -> " << qryChState.lastError().text(); qryChState.finish(); /* same result if write "WHERE" statement item with sysIdx=:p0 or sysIdx = 0 */ QSqlQuery qryChState(Database); qryChState.prepare("UPDATE state_machine SET peo=:p1, nasri=:p2, ena_a=:p3, mag_p=:p4, ace=:p5, s_vi=:p6, lisys=:p7, any_d=:p8, esp_bus=:p9, a_zero=:p10, ilda=:p11, ctB=:p12, aoB=:p13, debug=:p14, x_Off_b:=p15, y_Off_b=:p16, f_Off_b=:p17, biB=:p18, biC=:p19, aOff=:p20 WHERE sysIdx=:p0 "); qryChState.bindValue(":p0", w0); qryChState.bindValue(":p1", w1); qryChState.bindValue(":p2", w2); qryChState.bindValue(":p3", w3); qryChState.bindValue(":p4", w4); qryChState.bindValue(":p5", w5); qryChState.bindValue(":p6", w6); qryChState.bindValue(":p7", w7); qryChState.bindValue(":p8", w8); qryChState.bindValue(":p9", w9); qryChState.bindValue(":p10", w10); qryChState.bindValue(":p11", w11); qryChState.bindValue(":p12", w12); qryChState.bindValue(":p13", w13); qryChState.bindValue(":p14", w14); qryChState.bindValue(":p15", w15); qryChState.bindValue(":p16", w16); qryChState.bindValue(":p17", w17); qryChState.bindValue(":p18", w18); qryChState.bindValue(":p19", w19); qryChState.bindValue(":p20", w20); qryChState.exec(); qDebug() << "error update -> " << qryChState.lastError().text(); qryChState.finish(); error update -> "Parameter count mismatch"
But not understand why .... to avoid any problem I took the statment create of the table -> copy / paste -> and from that line I created the statment UPDATE, so as to avoid errors relating to the characters of the items name ... however the UPDATE does not work.
I use linux_Mint 18 and QT5.12 in that app .... all other query in app was SELECT, INSERT, DELETE .... and work all perfectly .... only these one not run ....
Appreciate any suggest .... regards
bkt -
Typo:
_Off_b:=p15
-
-
@gfxx Please mark the topic as solved then, thx.
-
@gfxx
For your future benefit. When you have a problem like this, the first thing to do is cut it down till it works, then build back up. For example, I would have cut yourUPDATE
statement in half, removing:p11
to:p20
and their bound variables from the statement. And cut in half again if that still did not work, down to:p0
only if necessary. Then when it is working, build back up by adding bits back in, till it went wrong again. We have all had long statements with some flaw we could not spot, this is the way to tackle such an issue.