我使用 SQLite Manager(firefox 插件)创建了一个 4 列和 5 行的表。现在我想借助以下代码从该表中获取整个随机行,但它不起作用,因为我以前从未使用过它。我可能做错了什么?
-(NSDictionary *)fetchQuestionsWithRowID:(NSInteger)rowID withDbPath:(NSString *)dbPath
{
NSDictionary *questDic=[NSDictionary dictionary];
sqlite3 *database=nil;
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
const char *sql = "SELECT * FROM quizQuestions Where rowid=?";
sqlite3_stmt *selectstmt;
int result = sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL);
if(result != SQLITE_OK) {
NSLog(@"Prepare-error #%i: %s", result, sqlite3_errmsg(database));
}
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK)
{
// confused here
sqlite3_bind_text16(selectstmt, 1, &rowID, -1, SQLITE_TRANSIENT);
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
NSString *str = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)];
NSLog(@"string is %@",str);
}
}
}
sqlite3_close(database);
return questDic;
}