我有数据库,但是当我试图从数据库中删除数据时没有任何反应,我应该怎么做才能确保它正常工作?因为当我按下删除时,数据仍在数据库中
这是代码:
/file path to database
-(NSString*)filePath {
NSArray*paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[paths objectAtIndex:0]stringByAppendingPathComponent:@"bp.sql"];
}
//open database
-(void)openDB {
if(sqlite3_open([[self filePath]UTF8String], &db) !=SQLITE_OK) {
sqlite3_close(db);
NSAssert(0, @"Databese failed to open");
}
else {
NSLog(@"database opemed");
}
}
- (IBAction)del:(id)sender {
NSString*sql = [NSString stringWithFormat:@"DELETE key, theDate, customer, code1, code2 FROM summary WHERE key=\"%@\"",customerName];
const char* query_stmt = [sql UTF8String];
sqlite3_stmt*statement;
sqlite3_prepare_v2(db, query_stmt, -1, & statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSAssert(0, @"database object delete failed");
} else {
NSLog(@"No error");
}
sqlite3_finalize(statement);
sqlite3_close(db)