XCODE SQLITE3自动增量删除和更新

时间:2015-09-13 06:49:12

标签: xcode sqlite sql-delete

我检查了一些关于在我的SQLITE3表中删除条目的在线资源 - 我认为我做错了,因为输出似乎不正确。

示例:ID AUTOINCREMENT PRIMARY KEY已定义。所以在删除(id = 3)之后我有id = 1,2,3,4。在新插入时,我实际上得到1,2,4,5而不是1,2,3,4 ...

任何人都可以请一些亮点吗?以下是我的代码。

p / s:我尝试了几种方法,这就是你可以看到注释命令的原因。

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        BP * bp = [entries objectAtIndex:indexPath.row];

        //[self deleteData:[NSString stringWithFormat:@"Delete from summary where name is '%s'", [bp.Diastolic UTF8String]]];
//        [self deleteData:[NSString stringWithFormat:@"Delete from summary where id is '%s'", [bp.IDNumber UTF8String]]];
//        [self deleteData:[NSString stringWithFormat:@"Delete from summary; delete from '%s' where name = summary",[bp.IDNumber UTF8String]]];
        [self deleteData:[NSString stringWithFormat:@"Delete from summary; delete from sqlite_sequence where name = summary"]];
        NSLog(@"Name %@ is deleted",bp.IDNumber);
        [entries removeObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

-(void)deleteData:(NSString *)deleteQuery
{
    char *error;

    if (sqlite3_exec(db, [deleteQuery UTF8String], NULL, NULL, &error)==SQLITE_OK) {
        NSLog(@"Entry deleted");
    }else{
        NSLog(@"Entry didn't delete");
    }
}

0 个答案:

没有答案