我无法删除记录。代码看起来不错,我在Xcode端没有出现任何错误,但是当我运行应用程序并尝试删除记录时,它会跳过if
并直接转到else
显示我的错误代码:
Error: Failed to delete contact.
我遵循了所有说明,所有其他功能都运作良好。我必须使用SQLite3进行删除。代码有什么问题?
- (IBAction)deleteData:(id)sender {
sqlite3_stmt *statement;
const char *dbpath = [_databasePath UTF8String];
if (sqlite3_open(dbpath, &_contactDB) == SQLITE_OK)
{
NSString *deleteSQL = [NSString stringWithFormat:@"DELETE FROM CONTACTS (name, address, phone)VALUES (\"%@\", \"%@\", \"%@\")",
self.name.text, self.address.text, self.phone.text];
const char *delete_stmt = [deleteSQL UTF8String];
sqlite3_prepare_v2(_contactDB, delete_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
self.status.text = @"Contact Deleted";
self.name.text = @"";
self.address.text = @"";
self.phone.text = @"";
} else {
self.status.text = @"Error! Failed to delete contact";
}
sqlite3_finalize(statement);
sqlite3_close(_contactDB);
}
}
答案 0 :(得分:0)