I am accessing nearly 30,000 words and showing in a table. The words are in a sqlite file. So it takes long time (15 seconds) to run the query and load the word in a table. Apparently the app wait 15 seconds in startup.
How can I get around this ?
NSLog(@"Query start");
CFTimeInterval startTime = CFAbsoluteTimeGetCurrent();
FMResultSet *rs = [db executeQuery:@"select * from words order by no ASC "];
while ([rs next]) {
Word *word = [[Word alloc] initWithID:[rs intForColumn:@"id"]
no:[rs stringForColumn:@"no"]
en:[rs stringForColumn:@"en"]];
[words addObject: word];
}
[rs close];
[db close];
CFTimeInterval endTime = CFAbsoluteTimeGetCurrent();
float deltaTimeInSeconds = endTime - startTime;
NSLog(@"Time spent for query: %f seconds", deltaTimeInSeconds);
NOTE: The original table is not sorted. It is a list of word for dictionary, so when to show, it must alphabetically sorted in the table view. that is why, I need to load all the words. A background thread may be a better idea, populate the data when fetching from sqlite. Does sqlite support this? Fetching data with a call back method. e.g. in the sqlite query, for each 1000 of records fetched, I'll update my table. I am not quite sure how to do that, if you know plz give me some tips.