I think there is only 2 ways to perform a QSqlQuery anyways, you either use either.
QString sql
= "SELECT * FROM people WHERE Name = '" + name
+ "' AND LastName = '" + lastname
+ "'";
QString name = "John";
QString lastname = "Smith";
QString sql = "SELECT * FROM people WHERE Name = '" + name + "' AND LastName = '" + lastname + "'";
QSqlQuery.exec(sql);
To copy to clipboard, switch view to plain text mode
or
you can prepare a statement then exec it..
QSqlQuery.
prepare("SELECT * FROM people WHERE Name = :name and LastName = :lastname); QSqlQuery.bindValue(":name", name);
QSqlQuery.bindValue(":lastname", lastname);
QSqlQuery.exec();
QSqlQuery.prepare("SELECT * FROM people WHERE Name = :name and LastName = :lastname);
QSqlQuery.bindValue(":name", name);
QSqlQuery.bindValue(":lastname", lastname);
QSqlQuery.exec();
To copy to clipboard, switch view to plain text mode
Note* Please correct me if there is another way, but this gets the job done for me.
I only use Prepare statements when inserting data other than text, like QByteArray / Data.
Bookmarks