我的数据库表中有 5 条记录,我需要显示第四条记录NSLog
,但它不会进入IF
代码语句。有人可以建议我错在哪里吗?
这是我的代码。
-(void) readFromDatabase {
[self checkAndCreateDatabase];
// Setup the database object
sqlite3 *database;
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from QuestionAnswers where Q.No = 4";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *questions = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *answers = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSLog(@"Questions:%@",questions);
NSLog(@"Answers:%@",answers);
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
提前致谢。