1
我有大問題。我的數據庫中有100000行(sqlite)。我現在不能減少這個數字。如何優化iphone上的sqlite(加載100000行)?
我使用下面的代碼從這個大表得到DataA的:開始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;
}
編輯:對不起,在數據庫:)
我知道我可以使用CoreData混合語言,但現在它爲時已晚。我可以做些什麼來優化這個查詢?因爲我必須爲每個表格單元格調用它,它非常非常緩慢。有沒有解決方法?
我不知道爲什麼它運行很慢。我有100000行,我只返回最大值。每個表格行最多50行(最多20行)。我的數據庫文件只有2.5 MB。不幸的是,返回對象並沒有提高性能。 – user968991
您的處理時間是由於第一次從數據庫中獲取數據,第二次是在tableView中加載數據。我通過創建一個用於從表中獲取數據並在mainThread中執行UILoading的新線程來解決同樣的問題。 –
非常感謝。我用這個:http://www.icodeblog.com/2010/03/04/iphone-coding-turbo-charging-your-apps-with-nsoperation/它很好(不完美,但足夠)。 – user968991