B2G/gecko/dom/base/IndexedDBHelper.jsm
/**
   * Open a new database.
   * User has to provide upgradeSchema.
   *
   * @param successCb
   *        Success callback to call once database is open.
   * @param failureCb
   *        Error callback to call when an error is encountered.
   */
Open a new database.
User has to provide upgradeSchema.

@param successCb
Success callback to call once database is open.
@param failureCb
Error callback to call when an error is encountered.
Open a new database . User has to provide upgradeSchema . @param successCb Success callback to call once database is open . @param failureCb Error callback to call when an error is encountered .
function open(aSuccessCb, aFailureCb) {
    let self = this;
    if (DEBUG) debug("Try to open database:" + self.dbName + " " + self.dbVersion);
    let req = this.dbGlobal.indexedDB.open(this.dbName, this.dbVersion);
    req.onsuccess = function (event) {
      if (DEBUG) debug("Opened database:" + self.dbName + " " + self.dbVersion);
      self._db = event.target.result;
      self._db.onversionchange = function(event) {
        if (DEBUG) debug("WARNING: DB modified from a different window.");
      }
      aSuccessCb();
    };
    req.onupgradeneeded = function (aEvent) {
      if (DEBUG) {
        debug("Database needs upgrade:" + self.dbName + aEvent.oldVersion + aEvent.newVersion);
        debug("Correct new database version:" + (aEvent.newVersion == this.dbVersion));
      }
      let _db = aEvent.target.result;
      self.upgradeSchema(req.transaction, _db, aEvent.oldVersion, aEvent.newVersion);
    };
    req.onerror = function (aEvent) {
      if (DEBUG) debug("Failed to open database:" + self.dbName);
      aFailureCb(aEvent.target.errorMessage);
    };
    req.onblocked = function (aEvent) {
      if (DEBUG) debug("Opening database request is blocked.");
    };
  }
function open ( aSuccessCb , aFailureCb ) { let self = this ; if ( DEBUG ) debug ( "Try to open database:" + self . dbName + " " + self . dbVersion ) ; let req = this . dbGlobal . indexedDB . open ( this . dbName , this . dbVersion ) ; req . onsuccess = function ( event ) { if ( DEBUG ) debug ( "Opened database:" + self . dbName + " " + self . dbVersion ) ; self . _db = event . target . result ; self . _db . onversionchange = function ( event ) { if ( DEBUG ) debug ( "WARNING: DB modified from a different window." ) ; } aSuccessCb ( ) ; } ; req . onupgradeneeded = function ( aEvent ) { if ( DEBUG ) { debug ( "Database needs upgrade:" + self . dbName + aEvent . oldVersion + aEvent . newVersion ) ; debug ( "Correct new database version:" + ( aEvent . newVersion == this . dbVersion ) ) ; } let _db = aEvent . target . result ; self . upgradeSchema ( req . transaction , _db , aEvent . oldVersion , aEvent . newVersion ) ; } ; req . onerror = function ( aEvent ) { if ( DEBUG ) debug ( "Failed to open database:" + self . dbName ) ; aFailureCb ( aEvent . target . errorMessage ) ; } ; req . onblocked = function ( aEvent ) { if ( DEBUG ) debug ( "Opening database request is blocked." ) ; } ; }
Open a new database.
Open a new database .