DBFlow - unable to delete data

1k Views Asked by At

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();
1

There are 1 best solutions below

1
On BEST ANSWER

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. :)