Note that there are some explanatory texts on larger screens.

plurals
  1. POdelete row from SQLite database with FMDB
    primarykey
    data
    text
    <p>i feel like i have read the docs for FMDB a million times. i am not sure why this code is not working - i have tried the executeUpdate method and the executeMethodWithFormat and their corresponding formats, neither seem to work. _dbArray is an array of dictionarys. these lines return the correct values - if i copy and paste the results and run the query in a terminal, it removes the record fine. am i missing something obvious?</p> <pre><code>- (IBAction)deleteDbEntry:(id)sender { // get selected row NSInteger row = [_dataTable selectedRow]; // get the entry number NSString *idToDelete = [[_dbArray objectAtIndex:row] valueForKey:@"entryColumn"]; // open DB for writing if (![db open]) { [db open]; } [db executeUpdate:@"DELETE FROM tbl1 WHERE entry = ?", idToDelete]; // close DB if ([db open]) { [db close]; } [_dataTable reloadData]; return; } </code></pre> <p>UPDATE: i have taken your suggestions and it is still not working, and I am not sure why. the opening and closing of the DB is happening elsewhere now (thank you @ccgus), and I am converting a string to an NSNumber (thanks @bryanmac). the <code>NSLog(@"myNumber is %@", myNumber);</code> call is returning the correct number, and i can confirm that the deletion is not happening. the <code>NSLog(@"Error %d: %@", [db lastErrorCode], [db lastErrorMessage]);</code> is reporting no errors (<code>Error 0: (null)</code>). i have also tried:</p> <p><code>[db executeUpdateWithFormat:@"DELETE FROM tbl1 WHERE entry = %@", myNumber];</code></p> <p>and </p> <p><code>[db executeUpdate:@"DELETE FROM tbl1 WHERE id = ?", [NSNumber numberWithInt:myNumber]];</code></p> <p>the first seems like it should work, but i have confirmed it does not delete the row. the second errors at me with "incompatible integer to pointer conversion". what am I missing?</p> <pre><code>- (IBAction)deleteDbEntry:(id)sender { // get selected row NSInteger row = [_dataTable selectedRow]; // get the entry number NSString *idToDelete = [[_dbArray objectAtIndex:row] valueForKey:@"entryColumn"]; NSNumberFormatter * f = [[NSNumberFormatter alloc] init]; [f setNumberStyle:NSNumberFormatterDecimalStyle]; NSNumber *myNumber = [f numberFromString:idToDelete]; NSLog(@"myNumber is %@", myNumber); [db executeUpdate:@"DELETE FROM tbl1 WHERE entry = ?", myNumber]; NSLog(@"Error %d: %@", [db lastErrorCode], [db lastErrorMessage]); [_dataTable reloadData]; return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload