2011-08-24 8 views
0

SQlite 데이터베이스에서 데이터를 삭제할 수 없습니다. 장소 데이터베이스를 만들었습니다. 그리고 UItableView에 표시 할 수 있습니다. 하지만 뭔가를 삭제하려고하면 코드가 충돌합니다.iPhone 응용 프로그램에서 SQLite 데이터베이스에서 데이터를 삭제할 수 없습니다.

내가 점점 오전 오류는 여기

Assertion failure in -[Place deleteFromDatabase], /Desktop/Current_cortes/Classes/Place.m:148

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: failed to prepare statement with message 'library routine called out of sequence'.

입니다 프로그램이 추락하는 부분입니다.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 

     NSLog(@"Rows can be edited"); 
     // Delete the row from the data source. 
     Place *PlaceObj = [appDelegate.PlacesArray objectAtIndex:indexPath.row]; 
     [appDelegate removePlace: PlaceObj]; 

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

    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
    } 
} 

[appDelegate removePlace: PlaceObj];과 함께 줄에 오류가 발생했습니다. 다음과 같이 removePlacedeleteFromDatabase

정의는 다음과 같습니다

(void) removePlace:(Place *)PlaceObj 
{ 

    NSLog(@"remove place called"); 
    //Delete it from the database. 
    [PlaceObj deleteFromDatabase]; 

    //Remove it from the array. 
    [PlacesArray removeObject:PlaceObj]; 
} 

-(void) deleteFromDatabase { 
    if (delete_statment == nil) { 
     const char *sql = "DELETE FROM places_table WHERE PlaceID=?"; 
     if (sqlite3_prepare_v2(database, sql, -1, &delete_statment, NULL) != SQLITE_OK) { 
      NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); 
     } 
    } 

    sqlite3_bind_int(delete_statment, 1, PlaceID); 
    int success = sqlite3_step(delete_statment); 

    if (success != SQLITE_DONE) { 
     NSAssert1(0, @"Error: failed to save priority with message '%s'.", sqlite3_errmsg(database)); 
    } 

    sqlite3_reset(delete_statment); 
} 

나는이 문제에 대한 봤 내가 다른 스레드에서 데이터베이스에 액세스하고 있기 때문에 될 수 있음을 발견했다. 코드가 시작되면 데이터베이스에서 읽을 수 있습니다. 그래서 데이터베이스에서 객체를 삭제할 수 있도록 무언가를 닫아야합니까?

답변

0

SQLite Database에 연결되어 있지 않습니다. 데이터베이스 연결을 확인하십시오.

+0

, 감사합니다 ... 보스 ... 어딘가에서 연결을 끊었으므로 삭제가 불가능했습니다. 고맙습니다 .... – amol

관련 문제