PDA

View Full Version : Update query



apffal
6th August 2009, 21:57
Cannot update a table with this code



QString str;
int ord = n_ord->text().toInt();
query = QSqlQuery ("UPDATE leg SET dip = '"+ str +"' WHERE n_ord = "+ ord +" LIMIT 1");


"n_ord" is an integer primary key table field and "ord" its actual value

Can someone helps ?
Thanks in advance

franz
7th August 2009, 07:05
What's the error you get?

lyuts
7th August 2009, 07:57
I suggest you use it this way



query = QSqlQuery (QString("UPDATE leg SET dip = '%1' WHERE n_ord = %2 LIMIT 1").arg(str).arg(ord));

apffal
7th August 2009, 12:16
It works, thank you !
Why does my previous code fail in QT ? In Java, for instance, it is correct ...

Lykurg
7th August 2009, 16:57
To avoid possible injections have a look at QSqlQuery::prepare().