B2G/gecko/toolkit/mozapps/extensions/XPIProviderUtils.js
/**
   * Creates the schema in the database.
   */
Creates the schema in the database.
Creates the schema in the database .
function XPIDB_createSchema() {
    LOG("Creating database schema");
    this.beginTransaction();
    try {
      this.connection.createTable("addon",
                                  "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                                  "id TEXT, syncGUID TEXT, " +
                                  "location TEXT, version TEXT, " +
                                  "type TEXT, internalName TEXT, updateURL TEXT, " +
                                  "updateKey TEXT, optionsURL TEXT, " +
                                  "optionsType TEXT, aboutURL TEXT, iconURL TEXT, " +
                                  "icon64URL TEXT, defaultLocale INTEGER, " +
                                  "visible INTEGER, active INTEGER, " +
                                  "userDisabled INTEGER, appDisabled INTEGER, " +
                                  "pendingUninstall INTEGER, descriptor TEXT, " +
                                  "installDate INTEGER, updateDate INTEGER, " +
                                  "applyBackgroundUpdates INTEGER, " +
                                  "bootstrap INTEGER, skinnable INTEGER, " +
                                  "size INTEGER, sourceURI TEXT, " +
                                  "releaseNotesURI TEXT, softDisabled INTEGER, " +
                                  "isForeignInstall INTEGER, " +
                                  "hasBinaryComponents INTEGER, " +
                                  "strictCompatibility INTEGER, " +
                                  "UNIQUE (id, location), " +
                                  "UNIQUE (syncGUID)");
      this.connection.createTable("targetApplication",
                                  "addon_internal_id INTEGER, " +
                                  "id TEXT, minVersion TEXT, maxVersion TEXT, " +
                                  "UNIQUE (addon_internal_id, id)");
      this.connection.createTable("targetPlatform",
                                  "addon_internal_id INTEGER, " +
                                  "os, abi TEXT, " +
                                  "UNIQUE (addon_internal_id, os, abi)");
      this.connection.createTable("addon_locale",
                                  "addon_internal_id INTEGER, "+
                                  "locale TEXT, locale_id INTEGER, " +
                                  "UNIQUE (addon_internal_id, locale)");
      this.connection.createTable("locale",
                                  "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                                  "name TEXT, description TEXT, creator TEXT, " +
                                  "homepageURL TEXT");
      this.connection.createTable("locale_strings",
                                  "locale_id INTEGER, type TEXT, value TEXT");
      this.connection.executeSimpleSQL("CREATE INDEX locale_strings_idx ON " +
        "locale_strings (locale_id)");
      this.connection.executeSimpleSQL("CREATE TRIGGER delete_addon AFTER DELETE " +
        "ON addon BEGIN " +
        "DELETE FROM targetApplication WHERE addon_internal_id=old.internal_id; " +
        "DELETE FROM targetPlatform WHERE addon_internal_id=old.internal_id; " +
        "DELETE FROM addon_locale WHERE addon_internal_id=old.internal_id; " +
        "DELETE FROM locale WHERE id=old.defaultLocale; " +
        "END");
      this.connection.executeSimpleSQL("CREATE TRIGGER delete_addon_locale AFTER " +
        "DELETE ON addon_locale WHEN NOT EXISTS " +
        "(SELECT * FROM addon_locale WHERE locale_id=old.locale_id) BEGIN " +
        "DELETE FROM locale WHERE id=old.locale_id; " +
        "END");
      this.connection.executeSimpleSQL("CREATE TRIGGER delete_locale AFTER " +
        "DELETE ON locale BEGIN " +
        "DELETE FROM locale_strings WHERE locale_id=old.id; " +
        "END");
      this.connection.schemaVersion = DB_SCHEMA;
      this.commitTransaction();
    }
    catch (e) {
      ERROR("Failed to create database schema", e);
      logSQLError(this.connection.lastError, this.connection.lastErrorString);
      this.rollbackTransaction();
      this.connection.close();
      this.connection = null;
      throw e;
    }
  }
function XPIDB_createSchema ( ) { LOG ( "Creating database schema" ) ; this . beginTransaction ( ) ; try { this . connection . createTable ( "addon" , "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " + "id TEXT, syncGUID TEXT, " + "location TEXT, version TEXT, " + "type TEXT, internalName TEXT, updateURL TEXT, " + "updateKey TEXT, optionsURL TEXT, " + "optionsType TEXT, aboutURL TEXT, iconURL TEXT, " + "icon64URL TEXT, defaultLocale INTEGER, " + "visible INTEGER, active INTEGER, " + "userDisabled INTEGER, appDisabled INTEGER, " + "pendingUninstall INTEGER, descriptor TEXT, " + "installDate INTEGER, updateDate INTEGER, " + "applyBackgroundUpdates INTEGER, " + "bootstrap INTEGER, skinnable INTEGER, " + "size INTEGER, sourceURI TEXT, " + "releaseNotesURI TEXT, softDisabled INTEGER, " + "isForeignInstall INTEGER, " + "hasBinaryComponents INTEGER, " + "strictCompatibility INTEGER, " + "UNIQUE (id, location), " + "UNIQUE (syncGUID)" ) ; this . connection . createTable ( "targetApplication" , "addon_internal_id INTEGER, " + "id TEXT, minVersion TEXT, maxVersion TEXT, " + "UNIQUE (addon_internal_id, id)" ) ; this . connection . createTable ( "targetPlatform" , "addon_internal_id INTEGER, " + "os, abi TEXT, " + "UNIQUE (addon_internal_id, os, abi)" ) ; this . connection . createTable ( "addon_locale" , "addon_internal_id INTEGER, " + "locale TEXT, locale_id INTEGER, " + "UNIQUE (addon_internal_id, locale)" ) ; this . connection . createTable ( "locale" , "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT, description TEXT, creator TEXT, " + "homepageURL TEXT" ) ; this . connection . createTable ( "locale_strings" , "locale_id INTEGER, type TEXT, value TEXT" ) ; this . connection . executeSimpleSQL ( "CREATE INDEX locale_strings_idx ON " + "locale_strings (locale_id)" ) ; this . connection . executeSimpleSQL ( "CREATE TRIGGER delete_addon AFTER DELETE " + "ON addon BEGIN " + "DELETE FROM targetApplication WHERE addon_internal_id=old.internal_id; " + "DELETE FROM targetPlatform WHERE addon_internal_id=old.internal_id; " + "DELETE FROM addon_locale WHERE addon_internal_id=old.internal_id; " + "DELETE FROM locale WHERE id=old.defaultLocale; " + "END" ) ; this . connection . executeSimpleSQL ( "CREATE TRIGGER delete_addon_locale AFTER " + "DELETE ON addon_locale WHEN NOT EXISTS " + "(SELECT * FROM addon_locale WHERE locale_id=old.locale_id) BEGIN " + "DELETE FROM locale WHERE id=old.locale_id; " + "END" ) ; this . connection . executeSimpleSQL ( "CREATE TRIGGER delete_locale AFTER " + "DELETE ON locale BEGIN " + "DELETE FROM locale_strings WHERE locale_id=old.id; " + "END" ) ; this . connection . schemaVersion = DB_SCHEMA ; this . commitTransaction ( ) ; } catch ( e ) { ERROR ( "Failed to create database schema" , e ) ; logSQLError ( this . connection . lastError , this . connection . lastErrorString ) ; this . rollbackTransaction ( ) ; this . connection . close ( ) ; this . connection = null ; throw e ; } }
Creates the schema in the database.
Creates the schema in the database .
// Any errors in here should rollback the transaction