我在.m文件中有以下代码,我可以到达NSLog在PREPARE之前说好的地方但我无法进入NSLog OK INSIDE PREPARE。 if语句行无效的问题是什么?我知道我有一个sqlite数据库。我有一张叫做学校的桌子。它在学校表中有一行数据。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
arrayOfSchools = [[NSMutableArray alloc]init];
[[self schoolTableView]setDelegate:self];
[[self schoolTableView]setDataSource:self];
sqlite3_stmt *statement;
if(sqlite3_open([dbPathString UTF8String], &eduLogDB)==SQLITE_OK){
[arrayOfSchools removeAllObjects];
NSString *querySql = [NSString stringWithFormat:@"SELECT * FROM school"];
const char *query_sql = [querySql UTF8String];
NSLog(@"OK BEFORE PEPARE");
if(sqlite3_prepare(eduLogDB, query_sql, -1, &statement, NULL)==SQLITE_OK){
NSLog(@"OK INSIDE PREPARE");
while (sqlite3_step(statement)==SQLITE_ROW){
NSString *schoolName = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement,1)];
School *school = [[School alloc]init];
[school setSchoolName:schoolName];
[arrayOfSchools addObject:school];
}
}
}
[[self schoolTableView]reloadData];
}