我在 ios 中做一个项目,我遇到了下一个问题:我正在使用现有的数据库,第一步(打开数据库)工作正常,但是当我尝试读取数据时出现错误。
控制台只显示:2013-02-26 14:46:59.999 MyApp[66537:c07] 读取数据问题
-(void) openDB
{
@try {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"data.db"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured.");
}
}
@catch (NSException *exception) {
NSLog(@"An exception occured: %@", [exception reason]);
}
}
-(void) getData{
NSString *sql = @"SELECT * FROM frases";
sqlite3_stmt * stmt;
if (sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil) != SQLITE_OK) {
NSLog(@"problem reading data");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self openDB];
[self getData];
}