Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a row in a sqlite database table?

I am using fmdb for managing my database. I could not find any example for deleting a row from a table in fmdb. I tried

  NSString *sqlStat=@"DELETE from tableName WHERE id=3";    
  FMResultSet *rs = [database executeQuery:sqlStat];

but its not working because when I checked the total number of entries in table, I am getting the same number as before executing the above statement. So, what is a proper way to delete a row from a table using fmdb?

like image 826
MAX Avatar asked Nov 08 '09 11:11

MAX


People also ask

How do I remove something from a table in SQLite?

The TRUNCATE TABLE statement is used to remove all records from a table. SQLite does not have an explicit TRUNCATE TABLE command like other databases. Instead, it has added a TRUNCATE optimizer to the DELETE statement. To truncate a table in SQLite, you just need to execute a DELETE statement without a WHERE clause.


1 Answers

FMDB can be a little finicky if you dont pass in the object as an NSNumber. This is the supported, and safe way of formatting queries.

[db executeUpdate:@"DELETE FROM theTable WHERE id = ?", [NSNumber numberWithInt:myObject.id]];
like image 141
coneybeare Avatar answered Sep 21 '22 00:09

coneybeare