【发布时间】:2010-02-14 03:03:34
【问题描述】:
我有以下方法在 iPhone 上查询 sqlite 数据库表 它从表中提取大约 6,000 行,然后根据这些信息循环创建 6,000 个对象并将它们填充到一个数组中。
while 循环有点慢(在我的设备上遍历它们大约需要 10 秒) 有什么想法可以加快速度吗?
TKS!!!
NSMutableArray *dees = [[NSMutableArray alloc] init];
if(sqlite3_open([database_path UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "select cn, gn, df, or, id from doits order by lower(cn)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
//loop through the results and feed them into the array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *a_cn = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
NSString *a_gn = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *a_df = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *an_or = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSString *ident = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)];
DL *dl = [[DL alloc] init];
dl.cn = a_cn;
dl.gn = a_gn;
dl.df = a_df;
dl.or = an_or;
dl.primary_id = [ident intValue];
[dees addObject:dl];
}
}
sqlite3_finalize(compiledStatement);
【问题讨论】:
标签: iphone sqlite nsmutablearray while-loop