I am trying to learn how to use SQLite with PyQt4. (And I am fairly new to both.)

My question is how do I check if any results were returned from a SELECT query?
At this point the only way I know to do this is to use
Qt Code:
  1. if query.next():
To copy to clipboard, switch view to plain text mode 
This however increments the query position. Now if I want to loop over the records in the query I can't use a standard loop unless unless I seek back to before the first record.
Qt Code:
  1. while query.next():
To copy to clipboard, switch view to plain text mode 

My second question is whether or not there will be a performance improvement using setForwardOnly (setForwardMode) with the SQLite driver. I will eventually have a database with ~10,000 entries and I will be doing repeated searches, so speed may be an issue. If there will be no improvement then using query.seek(-1) would work for me.

Here a snippet of what I want to do:
Qt Code:
  1. self.database = QtSql.QSqlDatabase.addDatabase("QSQLITE", "main")
  2. self.database.setDatabaseName(database_name)
  3. status = self.database.open()
  4.  
  5. self.query = QtSql.QSqlQuery(self.database)
  6.  
  7. self.query.prepare("SELECT id FROM track WHERE id=:id")
  8. self.query.bindValue(":id", QtCore.QVariant(id))
  9. self.query.exec_()
  10.  
  11. if self.query.next():
  12. self.query.seek(-1)
  13. # This next loop would be in an underlying function.
  14. while self.query.next():
  15. # Do some stuff.
  16. pass
To copy to clipboard, switch view to plain text mode 

- amicitas