Hello All,

I have a program that is running a lot of different SQL queries (mostly SELECT and UPDATE) and I was wondering what the best practice is for creating QSqlQuery objects.
Specifically: Should I create a separate object for each query, or reuse them?

For example:
Qt Code:
  1. QSqlQuery findBook("select title, author from books where id = 1");
  2. //some code...
  3.  
  4. QSqlQuery findMoreBooks("select title, author from books where pages > :pages");
  5. findMoreBooks.bindValue(":pages", 40);
  6. while(findMoreBooks.next()){
  7. //some more code..
  8. }
  9.  
  10. QSqlQuery updateABook("update books set title='foo' where id= :id");
  11.  
  12. QSqlQuery updateMoreBooks("update books set printable=0 where pages > 40");
To copy to clipboard, switch view to plain text mode 

Or I could do it like this:
Qt Code:
  1. QSqlQuery bookQuery;
  2.  
  3. bookQuery.prepare("select title, author from books where id = 1");
  4. bookQuery.exec();
  5. //some code...
  6. bookQuery.prepare("select title, author from books where pages > :pages");
  7. bookQuery.bindValue(":pages", 40);
  8. bookQuery.exec();
  9. while(bookQuery.next(){
  10. //some more code...
  11. }
  12.  
  13. bookQuery.prepare("update books set title='foo' where id=:id");
  14. bookQuery.exec();
  15. bookQuery.prepare("update books set printable=0 where pages > 40");
  16. bookQuery.exec();
To copy to clipboard, switch view to plain text mode 

Both seem to work, but I want to make sure I'm doing this the correct way.