Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.
This repository was archived by the owner on Aug 17, 2020. It is now read-only.

Any way to reload the database and make all observables to re-query? #39

@2buisson

Description

@2buisson

Reload SQLiteOpenHelper and re-query

In my app I have a import/export functionality, by importing, the SQLite database file is replaced by one on the sdcard, so I need to reload the SQLiteOpenHelper and then notify all the Queries.

Something like the following method would be really handy!

public void reloadDatabase(SQLiteOpenHelper helper, Set<String> tables){
   // Replace the SQLiteOpenHelper
   synchronized (databaseLock) {
      readableDatabase = null;
      writeableDatabase = null;
      this.helper.close();
      this.helper = helper;
   }
   // Make all Queries to reload
   sendTableTrigger(tables);
}

Or prehaps BriteDatabase can save a Set of tables, filled as we query them, to be notified on a potential database reload?

I guess I could make the user restart the app, but I rather not.

SQLBrite is amazing as it is very simple and allow us to get rid of loaders, and IMO notifying on tables is far better than the Uri system, thanks for creating SQLBrite!

Re-query only

Let's say my app is a calendar, I have an upcoming event list, starting by today's events.
In every event list I want to mark each yesterday's event as missed.

Then I need to reload event's Queries every day at 00:00.
In this particular case it would make sense to make the sendTableTrigger() public and call it every day.

I could also use a Observable.combineLatest with a Query and a PublishSubject and call this Subject every day to run the Query again, but since table triggers are managed the same way, it seems simple to switch sendTableTrigger() to public.

To support this idea; ContentResolver's notifyChange(Uri uri, null) is public.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions