I have loaded some data in my tableview using SQLite database in the format 1) some value, 2) some value so on. 1 and 2 are primary key, this is my code for delete which I have put on the swipe on delete function of the table view
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[self openDB];
NSString *idofTable = [NSString new];
NSScanner *scanner = [[NSScanner alloc] initWithString:[self.tableLogView cellForRowAtIndexPath:indexPath].textLabel.text];
[scanner scanUpToString:@")" intoString:&idofTable];
NSLog(@"id=%@, text=%@", idofTable, [self.tableLogView cellForRowAtIndexPath:indexPath].textLabel.text);
if(editingStyle==UITableViewCellEditingStyleDelete)
{
char *error;
NSString *sql = [NSString stringWithFormat:@"DELETE FROM History WHERE 'id' = '%@'", idofTable];
NSLog(@"%@",sql);
if(sqlite3_exec(db, [sql UTF8String], NULL, NULL,&error)!=SQLITE_OK)
{
sqlite3_close(db);
NSAssert(0,@"Could not create table");
}
else
{
NSLog(@"Data Deleted");
sqlite3_exec(db, "COMMIT", NULL, NULL, &error);
}
}
[tableLogView reloadData];
}
The log "Data Deleted" gets printed but the data doesnt get deleted in database nor in tableview. Any help appreciated. I dont know where the error is occuring, the query seems to be correct.