2010-10-24 123 views
0

UITableView中,我想刪除一行並刪除數據庫上的那一行,但是我的sqlite查詢不起作用。在SQLite中刪除行3

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
if (editingStyle == UITableViewCellEditingStyleDelete) { 
    UIAlertView *view; 

    sqlite3 *database; 
    int result = sqlite3_open("/quickdatabase.sqlite", &database); 
    if(result != SQLITE_OK) { 
     sqlite3_close(database); 
     view = [[UIAlertView alloc] initWithTitle:@"Database Error" message:@"Falha ao carregar o banco de dados.." delegate:self cancelButtonTitle:@"Cancelar" otherButtonTitles:nil]; 
     [view show]; 
     [view release]; 
     return; 
    } else { 
     NSString *query = [NSString stringWithFormat:@"DELETE FROM Enquetes WHERE Pergunta = '%@' AND Nome = '%@'", [arraySQL objectAtIndex:indexPath.row], [arrayAsk objectAtIndex:indexPath.row]]; 
     sqlite3_exec(database, [query UTF8String], NULL, NULL, NULL); 
     sqlite3_close(database); 

     view = [[UIAlertView alloc] initWithTitle:@"ArrayAsk" message:[arrayAsk objectAtIndex:indexPath.row] delegate:nil cancelButtonTitle:@"Cancelar" otherButtonTitles:nil]; 
     [view show]; 
     [view release]; 

     view = [[UIAlertView alloc] initWithTitle:@"ArraySQL" message:[arraySQL objectAtIndex:indexPath.row] delegate:nil cancelButtonTitle:@"Cancelar" otherButtonTitles:nil]; 
     [view show]; 
     [view release]; 

     [arrayAsk removeObjectAtIndex:indexPath.row]; 
     [arraySQL removeObjectAtIndex:indexPath.row]; 
     [tableView reloadData]; 
    } 
} 
} 

爲什麼不能正常工作?
我在哪裏可以看到FMDB框架的好教程?

回答

2

FMDB是在這裏:http://github.com/ccgus/fmdb/tree/master/src/

你正在尋找的樣本也就是頁面上;該示例是「fmdb.m」。

+0

+1爲鏈接 – 2010-10-24 02:29:14

+0

在該示例中,沒有關於要刪除的查詢的示例。只需插入,更新並創建一個新表。 – 2010-10-24 19:02:37

+0

將您的DELETE傳遞給executeUpdate,如示例的INSERT和CREATEs。 – 2010-10-24 20:32:18

0

嘗試FMDB

下載lib軟件包,看看包含的示例文件。