react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

Closing already closed database

Open mitevdev opened this issue 4 years ago • 0 comments

In my app I do not hold a reference to opened database while in foreground. Every time I open the database and close it after some operations. This leads to the following issue, when internally a database reference is reused and then closed, the next close call returns with error :

close: db name was not found in open databases: data.db
Specified db was not open

which is fine looking in the source code but closing not opened database should be more treated as warning but not as error. Much better way would be if there is a method to check if a database is already registered and then close it or add a second parameter to close() method specifying if an error should be thrown in case the specified database is not registered as opened.

What do you think?

PS. I've forgot to say - I do not use SQLitePlugin at all. I work directly with the native code from a typescript wrapper. The close method looks like:

  /**
   * Close the database.
   */
  public async close(): Promise<void> {
    return new Promise((resolve, reject) => {
      SQLite.close({ path: this.name }, () => resolve(), reject);
    });
  }

mitevdev avatar Apr 04 '20 08:04 mitevdev