Reputation: 31
I have big problem. I have 100000 rows in my database(sqlite). I can't reduce this number now.
I' m using following code to get dataa from this large table: wpis
-(NSMutableArray *) return_hours_for_near_two: (int) lacze : (int) hour :(int) okres {
NSString * query = [ NSString stringWithFormat:@"SELECT godzina, minuta FROM wpis WHERE liniaprzystanekid=%i AND okres=%i AND (godzina = %i OR godzina = %i)", lacze, okres, hour,hour+1];
NSLog(@"%@", query);
const char * querystring = [ query UTF8String];
NSMutableArray * temp = [ [NSMutableArray alloc] init];
sqlite3_stmt * statment;
if(sqlite3_prepare_v2(database, querystring, -1, &statment, nil) == SQLITE_OK){
while(sqlite3_step(statment) == SQLITE_ROW){
NSMutableArray * arr = [[[NSMutableArray alloc] init] autorelease];
[arr addObject:[NSNumber numberWithInt: sqlite3_column_int(statment, 0)]];
[arr addObject:[NSNumber numberWithInt: sqlite3_column_int(statment, 1)]];
[temp addObject:arr];
}
} else {
return NULL;
}
sqlite3_finalize(statment);
return temp;
}
EDIT: sorry for mixing languages in database :)
I know I could use CoreData, but now it is too late. What I can do to optimize this query? Because I must call it for every table cell and it's very, very slow. Is there any solution?
Upvotes: 1
Views: 1902
Reputation: 7733
Return the object instead of returning NSMutableArray It will process fast as compare to your NSMutableArray for 1000 lines.
You can also check this link:- What are the performance characteristics of sqlite with very large database files?
Upvotes: 1