我无法删除记录。代码看起来不错,我在 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);
}
}