0
我想完全清理我的iPhone應用程序中SQLite3表中的所有內容。我的MySQL經驗告訴我應該使用TRUNCATE。但似乎SQLite3不支持TRUNCATE(至少當我使用句子TRUNCATE my_table_Name準備語句時出現錯誤)。所以我轉向從刪除。兩個問題:1)將DELETE FROM徹底清理我的表嗎? 2)我試了下面的代碼,它的工作。但我高度懷疑其中有不必要甚至錯誤的代碼。任何人都可以幫我看看嗎?在iPhone上的SQLite3中截斷表?
在此先感謝。
迪
-(void)deleteAllUser {
NSString *ns_sql = [NSString stringWithFormat:@"DELETE FROM %@", [Config USER_TABLE_NAME]];
const char *sql = [ns_sql cStringUsingEncoding:NSUTF8StringEncoding];
sqlite3_stmt *statement = nil;
sqlite3* db = ...; //get the database instance
if(sqlite3_prepare_v2(db, sql, -1, &statement, nil) != SQLITE_OK) {
return;
}
//Without this line, table is not modified
int code = sqlite3_step(statement);
if (code == SQLITE_ROW) {
//Do nothing here...
}
sqlite3_finalize(statement);
}
謝謝Ishu,我會盡力的。 – 2010-12-22 06:37:27