Solved Qsqlite<--->sqlite3 qt5 select problem....lasterror return nothings ....
-
QSqlQuery Cset(db); Cset.prepare("SELECT a, b, c, a1, b1, c1, d, canny, e, f, g, h, nomepgr, m, n, o, p, q, gap, ip, port, mask, gain, exposure_abs, exposure, brightness, contrast, hue, saturation, white, framerate, autowhite, autogain, autoexposure, matrixptax, matrixptay, matrixptbx, matrixptby, matrixptcx, matrixptcy, matrixptdx, matrixptdy, rectax, rectay, rectbx, rectby, line, offsetxm, offsetym FROM val_chan WHERE id_val =:id_val"); Cset.bindValue(":id_val", ricId); /*** ricId is an integer****/ Cset.exec(); if( !Cset.exec() ) {qDebug() << "somethings is wrong ....";} /**** return always these messages*********/ yesterday these select work perfet ... but today I have add some new colum in table ...13 new colum ... and the select not work at all .... a try a lot of trik but nothings.... cset.lasterror return nothings .... regards Giorgio
-
Cset.exec(); // <- delete this line if( !Cset.exec() )
-
Hi!
The first thing to check is the returning error value (if any) from QSqlQuery. Just change your qDebug-line to
if( !Cset.exec() ) {qDebug() << "somethings is wrong ...." << Cset.lastError().text();}
-
Hi,
You should print the error returned by
Cset
to see what is going on.Out of curiosity, what's the size of that table ? What should it contain ?
[edit]: @VRonin's right, you're executing your query twice.
-
@ ALL ... thank for reply .....
firstly : ok 2time cset is only last try errer ...
second: i try other time to get lasterror ... never when i have add while cicle .... so now I get these error:QSqlError("", "Parameter count mismatch", "")
so I try to change in these way ....
QSqlQuery Cset(db); Cset.prepare("SELECT a, b, c, a1, b1, c1, d, canny, e, f, g, h, nomepgr, m, n, o, p, q, gap, ip, port, mask, gain, exposure_abs, exposure, brightness, contrast, hue, saturation, white, framerate, autowhite, autogain, autoexposure, matrixptax, matrixptay, matrixptbx, matrixptby, matrixptcx, matrixptcy, matrixptdx, matrixptdy, rectax, rectay, rectbx, rectby, line, offsetxm, offsetym FROM val_chan WHERE (:id_val)"); /*******<---- these change**********/ Cset.bindValue(":id_val", ricId); if( !Cset.exec() ) {qDebug() << "somethings is wrong ....";qDebug() << Cset.lastError(); } while (Cset.next()) { controlQuery ++; qDebug() << "controlQuery ++: " << controlQuery; a = Cset.value(0).toInt();
nothings change .....
@SGaist ... actually in the table there are only 10 row ... offsetxm, offsetym is real ... all other is integer and id_val obviusly is PKinteger ....
regards
giorgio -
Hi
First: You are sure you wanr your SQL-WHERE-clause like "WHERE (:id_val)" and not as above "WHERE id_val =:id_val"?
Second: Parameter mismatch usually means that your query is wrong. Check if all fieldnames are correct or provide us a database scheme if this doesn't help.
-
@Tschikkn Iread a pos where these problem was solved change "id_val = :id_val) to (:id_val) ......
this is my table....
CREATE TABLE val_chan ( "id_val" INTEGER NOT NULL, "a" INTEGER, "b" INTEGER, "c" INTEGER, "a1" INTEGER, "b1" INTEGER, "c1" INTEGER, "d" INTEGER, "canny" INTEGER, "e" INTEGER, "f" INTEGER, "g" INTEGER, "h" INTEGER, "nomepgr" TEXT, "m" INTEGER, "n" INTEGER, "o" INTEGER, "p" INTEGER, "q" INTEGER, "gap" INTEGER, "ip" TEXT, "port" TEXT, "mask" TEXT, "gain" INTEGER, "exposure_abs" INTEGER, "exposure" INTEGER, "brightness" INTEGER, "contrast" INTEGER, "hue" INTEGER, "saturation" INTEGER, "white" INTEGER, "framerate" INTEGER, "autowhite" INTEGER, "autogain" INTEGER, "autoexposure" INTEGER, "matrixptax" INTEGER, "matrixptay" INTEGER, "martixptbx" INTEGER, "matrixptby" INTEGER, "matrixptcx" INTEGER, "matrixptcy" INTEGER, "matrixptdx" INTEGER, "matrixptdy" INTEGER, "rectax" INTEGER, "rectay" INTEGER, "rectbx" INTEGER, "rectby" INTEGER, "line" INTEGER, "offsetxm" REAL, "offsetym" REAL
Regards
giorgio -
if you are getting all the fields anyway you can use
"SELECT * FROM val_chan WHERE id_val = :id_val"
and ignore the first column (i.e. start fromCset.value(1)
) -
@gfxx matrixptbx is not martixptbx INTEGER,
-
@Tschikkn Tanks a lot ..... yesterday night these solve my problem .... is not the first time I lose a lot of time for these things .... now is that I create a control input parser in bash ... input1 the list of column names, input2 my sql statement code snip .txt format, output a single column name + number of times it has been inserted ..... in this case I would find the "martixptbx" column with no. 1 while be nr. 2 ..... many thanks I owe you a beer ...;))
regards
Giorgio -
@gfxx Most of the time I'm having similiar problems while trying to code. It is hard to have a look "from outside" so you're welcome ;)