I'm trying to figure out what is the proper way to use prepared statements with QSqlQuery. The docs are not very specific on this subject.
query.prepare("SELECT * FROM theUniverse WHERE planet = :planet");
query.bindValue(":planet", "earth");
query.exec();
}
void select(const QSqlDatabase &database) {
QSqlQuery query(database);
query.prepare("SELECT * FROM theUniverse WHERE planet = :planet");
query.bindValue(":planet", "earth");
query.exec();
}
To copy to clipboard, switch view to plain text mode
So will this snippet create a permanent prepared statement in the connection database? Will this prepared statement persist between calls to select(), i.e. will it be saved when the function returns and QSqlQuery query is disposed?
Or should I create QSqlQuery on the heap and use the same instance over and over again?
Bookmarks