我在定位我的错误时遇到问题。代码可以通过 ID(init),我知道数据库正在加载。我的问题是 IF(sqlite3_prepare_v2...) 语句。当我运行代码时,这一行不 ==SQLITE_OK 而是跳到最后。任何帮助表示赞赏。谢谢。
@implementation CityState
static CityState *WDdatabase;
+(CityState *)WDdatabase {
if(WDdatabase == nil) {
WDdatabase = [[CityState alloc] init];
}
return WDdatabase;
}
- (id)init {
self = [super init];
if (self) {
NSString *sqliteDB = [[NSBundle mainBundle] pathForResource:@"CityAndState" ofType:@"sqlite"];
if(sqlite3_open([sqliteDB UTF8String], &WDdatebase) != SQLITE_OK){
NSLog(@"Failed to open database");
}
}
return self;
}
-(NSArray *)getAllCities {
NSMutableArray *returnArray = [[NSMutableArray alloc] init];
NSString *query = @"SELECT * FROM Test_Table";
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(WDdatebase, [query UTF8String], -1, &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
}
sqlite3_finalize(statement);
}
return returnArray;
}