PDA

View Full Version : QSQL error on insert into statement



Cyrebo
28th March 2013, 17:10
Hi, I'm working on a program where I get user input and insert that value to my database. At the moment, I'm getting the following error:
QSqlError(-1, "Unable to fetch row", "No query") But I know thats its not my coding because when I try a select statement, it works fine with no problems. My INSERT INTO statement is as follows:
str = pLineEdit->text();
QString qry = QString("INSERT INTO customer (name, phone_no, address, city) VALUES ('%%1%', NULL, NULL, NULL").arg(str);

Is my INSERT statement correct?

Cyrebo
28th March 2013, 22:11
Figured it out, syntax wasn't correct, all good and working now!

Lykurg
29th March 2013, 13:15
Good, but seriously take a look at QSqlQuery::prepare() to avoid SQL-Injections.

Cyrebo
29th March 2013, 17:03
Got it, thanks!