首先,我创建了“subjects.sqlite”并将其插入到 Xcode 文件“Copy Bundle Resrources”中
我用了这段代码
NSData *fetchedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.precaliga.com/iphone/subjects.sqlite"]];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"subjects.sqlite"];
[fetchedData writeToFile:filePath atomically:YES];
NSFileManager *fileMgr = [NSFileManager defaultManager];
BOOL success = [fileMgr fileExistsAtPath:filePath];
if (!success) {
NSLog(@"Cannot locate database file '%@'.", filePath);
}
else {
self.db = [DBController sharedDatabaseController:filePath];
DataTable* table = [_db ExecuteQuery:@"SELECT * FROM subjects"];
NSLog(@"%@",table.columns);
NSLog(@"Downloaded Successfuly ..");
}
但是“table.columns”返回
2013-04-12 11:34:06.202 Precaliga [82123:c07] ( )
因为它不会读取下载的 sqlite 文件。那么我如何在下载功能后读取数据
提前谢谢..请帮助我