我有以下代碼n我有4條記錄在數據庫中,但循環運行2次n只獲得第一行兩次我的代碼中有什麼問題?使用Sqlite Iphone在數據庫中插入行
- (void) getAllRowsFromTableName:(NSString *)tableName{
NSString *qsql = [NSString stringWithFormat:@"SELECT * FROM '%@'",tableName];
NSLog(@"query is :%@",qsql);
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(db,[qsql UTF8String] , -1, &statement,nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
NSLog(@"loop");
int catId = sqlite3_column_int(statement, 1);
NSLog(@"***CatId is :%d",catId);
sqlite3_finalize(statement);
}
sqlite3_finalize(statement);
}
嘗試以評論的sqlite3_finalize(聲明);在while循環中。 – Ravin 2012-03-01 14:22:04
是的,通過評論sqlite3_finalize(語句); while循環內我的代碼現在工作正常謝謝Ravin。 – user1242803 2012-03-01 14:30:57
@ user1242803:如果您滿意Ravin答案,請接受他的答案....查看此鏈接.. http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Aravindhan 2012-03-01 15:07:44