how to delete rows from GreenDao based on condition?
Asked Answered
T

1

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.

Taligrade answered 10/4, 2017 at 12:43 Comment(0)
S
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).

Shearwater answered 16/4, 2017 at 13:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.