数据从ios7.1中的sqlite db获取,但在使用ios 6.1时未获取

时间:2014-04-05 06:54:09

标签: ios objective-c database sqlite

我正在使用sqlite数据库从db获取数据到我的应用程序的UITableView.Data 在使用ios7.1模拟器时获取但在运行ios6.1模拟器时未获取数据。如何从同一个sqlite数据库的两个操作系统版本获取数据。

+(BOOL)copyFile{ 
NSString *strSourcePath=[[NSBundle mainBundle]pathForResource:@"Db" ofType:@"sqlite"];
NSString *strHome=NSHomeDirectory();
NSString *strDestPath=[NSString stringWithFormat:@"%@/Documents/NewDb.sqlite",strHome];
NSFileManager *manager=[NSFileManager defaultManager];
NSError *err;
if ([manager fileExistsAtPath:strDestPath]==NO) {
    [manager copyItemAtPath:strSourcePath toPath:strDestPath error:&err];
    return YES;
}
else{
    NSLog(@"file already exists");
    return NO;
}
return YES;
}

+(NSMutableArray*)getDetails{
NSString *strHome = NSHomeDirectory();
NSString *strDestPath = [NSString stringWithFormat:@"%@/Documents/NewDb.sqlite",strHome];
NSMutableArray *arrDetails=[[NSMutableArray alloc]init];
sqlite3 *db;
int n = sqlite3_open([strDestPath UTF8String], &db);
if (n==SQLITE_OK) {
    NSString *strQuery=@"SELECT * FROM Categories";
    sqlite3_stmt *stmt;
    char *err_msg;

    int res=sqlite3_prepare_v2(db, [strQuery UTF8String], -1, &stmt, &err_msg);
    if (res == SQLITE_OK) {
        while (sqlite3_step(stmt)==SQLITE_ROW) {

            Categories *categories=[[Categories alloc]init];
            categories.categoryId=sqlite3_column_int(stmt,0);
            categories.categoryName=[NSString stringWithUTF8String:(char *) sqlite3_column_text(stmt, 1)];
            categories.categoryImage=[NSString stringWithUTF8String:(char *) sqlite3_column_text(stmt, 2)];
            [arrDetails addObject:categories];

        }
    }
}
return arrDetails;
}

0 个答案:

没有答案