I am trying to use SQLite in a PyQt4 application. I am running into a problem where it is taking a really long time to get the data out of the QSqlQuery object after a query is completed. Here is a code snippet with the relevant parts:
# Begin Snippet
self.selected_columns = self.table_definition['track']
select_string = ','.join(self.selected_columns)
query_str = 'SELECT %s FROM track %s'%(select_string, where_string)
start_time = time.clock()
self.query.prepare(query_str)
self.query.exec_()
util.message('Query took:', time.clock() - start_time, 'seconds')
print ''
print query_str
results = []
header = self.selected_columns
self.query.first()
while self.query.isValid():
record = [self.query.value(index).toString() for index in range(len(header))]
results.append(record)
self.query.next()
util.message('Selected', len(results), 'records.')
util.message('Unpacking Took:', time.clock() - start_time, 'seconds')
# Begin Snippet
self.selected_columns = self.table_definition['track']
select_string = ','.join(self.selected_columns)
query_str = 'SELECT %s FROM track %s'%(select_string, where_string)
start_time = time.clock()
self.query.prepare(query_str)
self.query.exec_()
util.message('Query took:', time.clock() - start_time, 'seconds')
print ''
print query_str
results = []
header = self.selected_columns
self.query.first()
while self.query.isValid():
record = [self.query.value(index).toString() for index in range(len(header))]
results.append(record)
self.query.next()
util.message('Selected', len(results), 'records.')
util.message('Unpacking Took:', time.clock() - start_time, 'seconds')
To copy to clipboard, switch view to plain text mode
While the query is quick, extracting the data takes a really long time. Way longer than I think it should take.
Here are the results:
Query took: 0.00094797466213 seconds
SELECT artist,album,title,url,musicbrainz_trackid,hystrix_trackid FROM track
Selected 16668 records.
Unpacking Took: 5.29902267251 seconds
Query took: 0.00094797466213 seconds
SELECT artist,album,title,url,musicbrainz_trackid,hystrix_trackid FROM track
Selected 16668 records.
Unpacking Took: 5.29902267251 seconds
To copy to clipboard, switch view to plain text mode
Query took: 0.0317866355896 seconds
SELECT artist,album,title,url,musicbrainz_trackid,hystrix_trackid FROM track WHERE (album LIKE '%it%' OR title LIKE '%it%' OR artist LIKE '%it%')
Selected 3262 records.
Unpacking Took: 1.4495204451 seconds
Query took: 0.0317866355896 seconds
SELECT artist,album,title,url,musicbrainz_trackid,hystrix_trackid FROM track WHERE (album LIKE '%it%' OR title LIKE '%it%' OR artist LIKE '%it%')
Selected 3262 records.
Unpacking Took: 1.4495204451 seconds
To copy to clipboard, switch view to plain text mode
I have tried using setForwardOnly() but it made no difference.
Does anyone have any idea on why this is taking so long or how I can improve things?
-- amicitas
Hystrix Audio
Bookmarks