Search code examples
androidandroid-databasedbflow

DBFlow - unable to delete data


I'm using DBFlow to manage my database in Android. I'm trying to delete a record based on a query. When I execute the following code, I don't get an error but the record still persists.

Anything I'm doing obviously wrong ?

SQLite.select()
      .from(Person.class)
      .where(query)
      .async()
      .querySingleResultCallback(new QueryTransaction.QueryResultSingleCallback<Person>() {
                @Override
                public void onSingleQueryResult(QueryTransaction transaction, @Nullable Person person) {

                    person.delete();
                }
            })
      .error(new Transaction.Error() {
                    @Override
                    public void onError(Transaction transaction, Throwable error) {

                        Exception ex = new Exception(error);
                        callback.onError(ex);
                    }
                })
       .success(new Transaction.Success() {
                    @Override
                    public void onSuccess(@NonNull Transaction transaction) {
                        callback.onSuccess();
                    }
                })
       .execute();

Solution

  • You are fetching data from db to RAM and then deleting from RAM. It wont remove from actual db.

    try this

    SQLite.delete(Person.class)
    .where(query)
    .async()
    .execute();
    

    Helpful Guide Link for DBFlow

    Hope this help. :)