B2G/gecko/toolkit/mozapps/extensions/XPIProviderUtils.js
/**
   * Retrieves migration data from a database that has an older or newer schema.
   *
   * @return an object holding information about what add-ons were previously
   *         userDisabled and any updated compatibility information
   */
Retrieves migration data from a database that has an older or newer schema.
@return an object holding information about what add-ons were previously
userDisabled and any updated compatibility information
Retrieves migration data from a database that has an older or newer schema . @return an object holding information about what add - ons were previously userDisabled and any updated compatibility information
function XPIDB_getMigrateDataFromDatabase() {
    let migrateData = {};
    try {
      var stmt = this.connection.createStatement("PRAGMA table_info(addon)");
      const REQUIRED = ["internal_id", "id", "location", "userDisabled",
                        "installDate", "version"];
      let reqCount = 0;
      let props = [];
      for (let row in resultRows(stmt)) {
        if (REQUIRED.indexOf(row.name) != -1) {
          reqCount++;
          props.push(row.name);
        }
        else if (DB_METADATA.indexOf(row.name) != -1) {
          props.push(row.name);
        }
        else if (DB_BOOL_METADATA.indexOf(row.name) != -1) {
          props.push(row.name);
        }
      }
      if (reqCount < REQUIRED.length) {
        ERROR("Unable to read anything useful from the database");
        return null;
      }
      stmt.finalize();
      stmt = this.connection.createStatement("SELECT " + props.join(",") + " FROM addon");
      for (let row in resultRows(stmt)) {
        if (!(row.location in migrateData))
          migrateData[row.location] = {};
        let addonData = {
          targetApplications: []
        }
        migrateData[row.location][row.id] = addonData;
        props.forEach(function(aProp) {
          if (DB_BOOL_METADATA.indexOf(aProp) != -1)
            addonData[aProp] = row[aProp] == 1;
          else
            addonData[aProp] = row[aProp];
        })
      }
      var taStmt = this.connection.createStatement("SELECT id, minVersion, " +
                                                   "maxVersion FROM " +
                                                   "targetApplication WHERE " +
                                                   "addon_internal_id=:internal_id");
      for (let location in migrateData) {
        for (let id in migrateData[location]) {
          taStmt.params.internal_id = migrateData[location][id].internal_id;
          delete migrateData[location][id].internal_id;
          for (let row in resultRows(taStmt)) {
            migrateData[location][id].targetApplications.push({
              id: row.id,
              minVersion: row.minVersion,
              maxVersion: row.maxVersion
            });
          }
        }
      }
    }
    catch (e) {
      ERROR("Error migrating data", e);
      return null;
    }
    finally {
      if (taStmt)
        taStmt.finalize();
      if (stmt)
        stmt.finalize();
    }
    return migrateData;
  }
function XPIDB_getMigrateDataFromDatabase ( ) { let migrateData = { } ; try { var stmt = this . connection . createStatement ( "PRAGMA table_info(addon)" ) ; const REQUIRED = [ "internal_id" , "id" , "location" , "userDisabled" , "installDate" , "version" ] ; let reqCount = 0 ; let props = [ ] ; for ( let row in resultRows ( stmt ) ) { if ( REQUIRED . indexOf ( row . name ) != - 1 ) { reqCount ++ ; props . push ( row . name ) ; } else if ( DB_METADATA . indexOf ( row . name ) != - 1 ) { props . push ( row . name ) ; } else if ( DB_BOOL_METADATA . indexOf ( row . name ) != - 1 ) { props . push ( row . name ) ; } } if ( reqCount < REQUIRED . length ) { ERROR ( "Unable to read anything useful from the database" ) ; return null ; } stmt . finalize ( ) ; stmt = this . connection . createStatement ( "SELECT " + props . join ( "," ) + " FROM addon" ) ; for ( let row in resultRows ( stmt ) ) { if ( ! ( row . location in migrateData ) ) migrateData [ row . location ] = { } ; let addonData = { targetApplications : [ ] } migrateData [ row . location ] [ row . id ] = addonData ; props . forEach ( function ( aProp ) { if ( DB_BOOL_METADATA . indexOf ( aProp ) != - 1 ) addonData [ aProp ] = row [ aProp ] == 1 ; else addonData [ aProp ] = row [ aProp ] ; } ) } var taStmt = this . connection . createStatement ( "SELECT id, minVersion, " + "maxVersion FROM " + "targetApplication WHERE " + "addon_internal_id=:internal_id" ) ; for ( let location in migrateData ) { for ( let id in migrateData [ location ] ) { taStmt . params . internal_id = migrateData [ location ] [ id ] . internal_id ; delete migrateData [ location ] [ id ] . internal_id ; for ( let row in resultRows ( taStmt ) ) { migrateData [ location ] [ id ] . targetApplications . push ( { id : row . id , minVersion : row . minVersion , maxVersion : row . maxVersion } ) ; } } } } catch ( e ) { ERROR ( "Error migrating data" , e ) ; return null ; } finally { if ( taStmt ) taStmt . finalize ( ) ; if ( stmt ) stmt . finalize ( ) ; } return migrateData ; }
Retrieves migration data from a database that has an older or newer schema.
Retrieves migration data from a database that has an older or newer schema .
// Attempt to migrate data from a different (even future!) version of the // database // An error here means the schema is too different to read