0

Can you spot anything that would cause this to not work?

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
 int record_to_delete = [[[data objectAtIndex:indexPath.row] recordID] integerValue];
 [data removeObjectAtIndex:indexPath.row];
 [self.tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:YES];
 //Delete from TABLENAME where CRITERIA1=VALUE1 (AND CRITERIA2=VALUE2...)
 //Delete from Data where RecordID=xxx
 sqlite3 *database;
 if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
 NSString *sqlStatement = [NSString stringWithFormat:@"delete from Data where RecordID = %d",record_to_delete];
 NSLog(@"Statement is: %@", sqlStatement);
 sqlite3_stmt *compiledStatement;
 NSLog(@"Statement");
 if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK){
 }
 NSLog(@"Deleting");
 sqlite3_finalize(compiledStatement);
 NSLog(@"Deleted");
 }
 sqlite3_close(database);
}
}

The SQL statement works fine when executed in my database software. However when run on the iPhone simulator it does not delete it from the Database. Any help would be greatly appreciated. Sorry I can't be more specific.

Thanks

2013年03月18日 18:45:07.211 Navigation[842:c07] Statement is: delete from Data where RecordID = 1
2013年03月18日 18:45:07.212 Navigation[842:c07] Statement
2013年03月18日 18:45:07.212 Navigation[842:c07] Deleting
2013年03月18日 18:45:07.213 Navigation[842:c07] Deleted

UPDATE: Managed to get it to work. I was just missing.

sqlite3_step(compiledStatement)

Thanks anyway.

rmaddy
320k44 gold badges548 silver badges591 bronze badges
asked Mar 18, 2013 at 18:37
2
  • is opened database ? could u please include logs along with ur question ? Commented Mar 18, 2013 at 18:41
  • 1
    It is news to me that xcode deletes databases on devices. Commented Mar 18, 2013 at 18:41

1 Answer 1

1

In iOS you don't have write access to the app bundle. The suggested way is to copy the database into the document folder at the first time you run the app, and then manage the database from there.

Look here: Unable to connect SQLite Database in iOS

answered Mar 18, 2013 at 18:45
Sign up to request clarification or add additional context in comments.

4 Comments

How would I copy it into the document folder?
I added a link to an useful question.
I'm pretty sure my database is already open. Because everything is being displayed from the database. It's just the delete part that doesn't seem to work.
In your case you can open it, so you have read access but not write access. The answer explains how to copy the database to the document folder, try it.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.