B2G/gecko/toolkit/mozapps/extensions/XPIProviderUtils.js
/**
   * Attempts to open the database file. If it fails it will try to delete the
   * existing file and create an empty database. If that fails then it will
   * open an in-memory database that can be used during this session.
   *
   * @param  aDBFile
   *         The nsIFile to open
   * @return the mozIStorageConnection for the database
   */
Attempts to open the database file. If it fails it will try to delete the
existing file and create an empty database. If that fails then it will
open an in-memory database that can be used during this session.

@param  aDBFile
The nsIFile to open
@return the mozIStorageConnection for the database
Attempts to open the database file . If it fails it will try to delete the existing file and create an empty database . If that fails then it will open an in - memory database that can be used during this session . @param aDBFile The nsIFile to open @return the mozIStorageConnection for the database
function XPIDB_openDatabaseFile(aDBFile) {
    LOG("Opening database");
    let connection = null;
    try {
      connection = Services.storage.openUnsharedDatabase(aDBFile);
      this.dbfileExists = true;
    }
    catch (e) {
      ERROR("Failed to open database (1st attempt)", e);
      if (e.result != Cr.NS_ERROR_STORAGE_BUSY) {
        try {
          aDBFile.remove(true);
        }
        catch (e) {
          ERROR("Failed to remove database that could not be opened", e);
        }
        try {
          connection = Services.storage.openUnsharedDatabase(aDBFile);
        }
        catch (e) {
          ERROR("Failed to open database (2nd attempt)", e);
          return Services.storage.openSpecialDatabase("memory");
        }
      }
      else {
        return Services.storage.openSpecialDatabase("memory");
      }
    }
    connection.executeSimpleSQL("PRAGMA synchronous = FULL");
    connection.executeSimpleSQL("PRAGMA locking_mode = EXCLUSIVE");
    return connection;
  }
function XPIDB_openDatabaseFile ( aDBFile ) { LOG ( "Opening database" ) ; let connection = null ; try { connection = Services . storage . openUnsharedDatabase ( aDBFile ) ; this . dbfileExists = true ; } catch ( e ) { ERROR ( "Failed to open database (1st attempt)" , e ) ; if ( e . result != Cr . NS_ERROR_STORAGE_BUSY ) { try { aDBFile . remove ( true ) ; } catch ( e ) { ERROR ( "Failed to remove database that could not be opened" , e ) ; } try { connection = Services . storage . openUnsharedDatabase ( aDBFile ) ; } catch ( e ) { ERROR ( "Failed to open database (2nd attempt)" , e ) ; return Services . storage . openSpecialDatabase ( "memory" ) ; } } else { return Services . storage . openSpecialDatabase ( "memory" ) ; } } connection . executeSimpleSQL ( "PRAGMA synchronous = FULL" ) ; connection . executeSimpleSQL ( "PRAGMA locking_mode = EXCLUSIVE" ) ; return connection ; }
Attempts to open the database file.
Attempts to open the database file .
// Attempt to open the database // If the database was locked for some reason then assume it still // has some good data and we should try to load it the next time around. // If we have got here there seems to be no way to open the real // database, instead open a temporary memory database so things will // work for this session.