6

i want to delete rows from a table based on condition. like

"delete from Table where Name='Value'"

here i am using greenDAO database.

rashmi ranjan
  • 380
  • 1
  • 4
  • 14

1 Answers1

14

1 Check the documentation.

2 Create a DeleteQuery for your Table

3 Execute it

4 Clear the session so that all caches lose the deleted objects too.

final DeleteQuery<Table> tableDeleteQuery = daoSession.queryBuilder(Table.class)
.where(TableDao.Properties.Name.eq("Value"))
.buildDelete();
tableDeleteQuery.executeDeleteWithoutDetachingEntities();
daoSession.clear();

If you need to execute the query multiple times, save the query object to avoid re-instantiating it.

Btw greenDAO is an ORM, not a database (here it's SQLite).

w_n
  • 345
  • 3
  • 7