зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1057901 - Adopt template strings for SQL statements in content preferences. r=adw
This commit is contained in:
Родитель
d217075421
Коммит
154ca34e75
|
@ -32,6 +32,13 @@ Cu.import("resource://gre/modules/Services.jsm");
|
|||
Cu.import("resource://gre/modules/ContentPrefUtils.jsm");
|
||||
Cu.import("resource://gre/modules/ContentPrefStore.jsm");
|
||||
|
||||
const GROUP_CLAUSE = `
|
||||
SELECT id
|
||||
FROM groups
|
||||
WHERE name = :group OR
|
||||
(:includeSubdomains AND name LIKE :pattern ESCAPE '/')
|
||||
`;
|
||||
|
||||
function ContentPrefService2(cps) {
|
||||
this._cps = cps;
|
||||
this._cache = cps._cache;
|
||||
|
@ -56,21 +63,21 @@ ContentPrefService2.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
let stmt1 = this._stmt(
|
||||
"SELECT groups.name AS grp, prefs.value AS value",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"JOIN groups ON groups.id = prefs.groupID",
|
||||
"WHERE settings.name = :name"
|
||||
);
|
||||
let stmt1 = this._stmt(`
|
||||
SELECT groups.name AS grp, prefs.value AS value
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
JOIN groups ON groups.id = prefs.groupID
|
||||
WHERE settings.name = :name
|
||||
`);
|
||||
stmt1.params.name = name;
|
||||
|
||||
let stmt2 = this._stmt(
|
||||
"SELECT NULL AS grp, prefs.value AS value",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"WHERE settings.name = :name AND prefs.groupID ISNULL"
|
||||
);
|
||||
let stmt2 = this._stmt(`
|
||||
SELECT NULL AS grp, prefs.value AS value
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
WHERE settings.name = :name AND prefs.groupID ISNULL
|
||||
`);
|
||||
stmt2.params.name = name;
|
||||
|
||||
this._execStmts([stmt1, stmt2], {
|
||||
|
@ -154,31 +161,27 @@ ContentPrefService2.prototype = {
|
|||
|
||||
_commonGetStmt: function CPS2__commonGetStmt(group, name, includeSubdomains) {
|
||||
let stmt = group ?
|
||||
this._stmtWithGroupClause(group, includeSubdomains,
|
||||
"SELECT groups.name AS grp, prefs.value AS value",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"JOIN groups ON groups.id = prefs.groupID",
|
||||
"WHERE settings.name = :name AND prefs.groupID IN ($)"
|
||||
) :
|
||||
this._stmt(
|
||||
"SELECT NULL AS grp, prefs.value AS value",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"WHERE settings.name = :name AND prefs.groupID ISNULL"
|
||||
);
|
||||
this._stmtWithGroupClause(group, includeSubdomains, `
|
||||
SELECT groups.name AS grp, prefs.value AS value
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
JOIN groups ON groups.id = prefs.groupID
|
||||
WHERE settings.name = :name AND prefs.groupID IN (${GROUP_CLAUSE})
|
||||
`) :
|
||||
this._stmt(`
|
||||
SELECT NULL AS grp, prefs.value AS value
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
WHERE settings.name = :name AND prefs.groupID ISNULL
|
||||
`);
|
||||
stmt.params.name = name;
|
||||
return stmt;
|
||||
},
|
||||
|
||||
_stmtWithGroupClause: function CPS2__stmtWithGroupClause(group,
|
||||
includeSubdomains) {
|
||||
let stmt = this._stmt(joinArgs(Array.slice(arguments, 2)).replace("$",
|
||||
"SELECT id " +
|
||||
"FROM groups " +
|
||||
"WHERE name = :group OR " +
|
||||
"(:includeSubdomains AND name LIKE :pattern ESCAPE '/')"
|
||||
));
|
||||
includeSubdomains,
|
||||
sql) {
|
||||
let stmt = this._stmt(sql);
|
||||
stmt.params.group = group;
|
||||
stmt.params.includeSubdomains = includeSubdomains || false;
|
||||
stmt.params.pattern = "%." + stmt.escapeStringForLIKE(group, "/");
|
||||
|
@ -263,53 +266,53 @@ ContentPrefService2.prototype = {
|
|||
let stmts = [];
|
||||
|
||||
// Create the setting if it doesn't exist.
|
||||
let stmt = this._stmt(
|
||||
"INSERT OR IGNORE INTO settings (id, name)",
|
||||
"VALUES((SELECT id FROM settings WHERE name = :name), :name)"
|
||||
);
|
||||
let stmt = this._stmt(`
|
||||
INSERT OR IGNORE INTO settings (id, name)
|
||||
VALUES((SELECT id FROM settings WHERE name = :name), :name)
|
||||
`);
|
||||
stmt.params.name = name;
|
||||
stmts.push(stmt);
|
||||
|
||||
// Create the group if it doesn't exist.
|
||||
if (group) {
|
||||
stmt = this._stmt(
|
||||
"INSERT OR IGNORE INTO groups (id, name)",
|
||||
"VALUES((SELECT id FROM groups WHERE name = :group), :group)"
|
||||
);
|
||||
stmt = this._stmt(`
|
||||
INSERT OR IGNORE INTO groups (id, name)
|
||||
VALUES((SELECT id FROM groups WHERE name = :group), :group)
|
||||
`);
|
||||
stmt.params.group = group;
|
||||
stmts.push(stmt);
|
||||
}
|
||||
|
||||
// Finally create or update the pref.
|
||||
if (group) {
|
||||
stmt = this._stmt(
|
||||
"INSERT OR REPLACE INTO prefs (id, groupID, settingID, value)",
|
||||
"VALUES(",
|
||||
"(SELECT prefs.id",
|
||||
"FROM prefs",
|
||||
"JOIN groups ON groups.id = prefs.groupID",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"WHERE groups.name = :group AND settings.name = :name),",
|
||||
"(SELECT id FROM groups WHERE name = :group),",
|
||||
"(SELECT id FROM settings WHERE name = :name),",
|
||||
":value",
|
||||
")"
|
||||
);
|
||||
stmt = this._stmt(`
|
||||
INSERT OR REPLACE INTO prefs (id, groupID, settingID, value)
|
||||
VALUES(
|
||||
(SELECT prefs.id
|
||||
FROM prefs
|
||||
JOIN groups ON groups.id = prefs.groupID
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
WHERE groups.name = :group AND settings.name = :name),
|
||||
(SELECT id FROM groups WHERE name = :group),
|
||||
(SELECT id FROM settings WHERE name = :name),
|
||||
:value
|
||||
)
|
||||
`);
|
||||
stmt.params.group = group;
|
||||
}
|
||||
else {
|
||||
stmt = this._stmt(
|
||||
"INSERT OR REPLACE INTO prefs (id, groupID, settingID, value)",
|
||||
"VALUES(",
|
||||
"(SELECT prefs.id",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"WHERE prefs.groupID IS NULL AND settings.name = :name),",
|
||||
"NULL,",
|
||||
"(SELECT id FROM settings WHERE name = :name),",
|
||||
":value",
|
||||
")"
|
||||
);
|
||||
stmt = this._stmt(`
|
||||
INSERT OR REPLACE INTO prefs (id, groupID, settingID, value)
|
||||
VALUES(
|
||||
(SELECT prefs.id
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
WHERE prefs.groupID IS NULL AND settings.name = :name),
|
||||
NULL,
|
||||
(SELECT id FROM settings WHERE name = :name),
|
||||
:value
|
||||
)
|
||||
`);
|
||||
}
|
||||
stmt.params.name = name;
|
||||
stmt.params.value = value;
|
||||
|
@ -365,29 +368,29 @@ ContentPrefService2.prototype = {
|
|||
stmts.push(this._commonGetStmt(group, name, includeSubdomains));
|
||||
|
||||
// Delete the matching prefs.
|
||||
let stmt = this._stmtWithGroupClause(group, includeSubdomains,
|
||||
"DELETE FROM prefs",
|
||||
"WHERE settingID = (SELECT id FROM settings WHERE name = :name) AND",
|
||||
"CASE typeof(:group)",
|
||||
"WHEN 'null' THEN prefs.groupID IS NULL",
|
||||
"ELSE prefs.groupID IN ($)",
|
||||
"END"
|
||||
);
|
||||
let stmt = this._stmtWithGroupClause(group, includeSubdomains, `
|
||||
DELETE FROM prefs
|
||||
WHERE settingID = (SELECT id FROM settings WHERE name = :name) AND
|
||||
CASE typeof(:group)
|
||||
WHEN 'null' THEN prefs.groupID IS NULL
|
||||
ELSE prefs.groupID IN (${GROUP_CLAUSE})
|
||||
END
|
||||
`);
|
||||
stmt.params.name = name;
|
||||
stmts.push(stmt);
|
||||
|
||||
// Delete settings and groups that are no longer used. The NOTNULL term in
|
||||
// the subquery of the second statment is needed because of SQLite's weird
|
||||
// IN behavior vis-a-vis NULLs. See http://sqlite.org/lang_expr.html.
|
||||
stmts.push(this._stmt(
|
||||
"DELETE FROM settings",
|
||||
"WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)"
|
||||
));
|
||||
stmts.push(this._stmt(
|
||||
"DELETE FROM groups WHERE id NOT IN (",
|
||||
"SELECT DISTINCT groupID FROM prefs WHERE groupID NOTNULL",
|
||||
")"
|
||||
));
|
||||
stmts.push(this._stmt(`
|
||||
DELETE FROM settings
|
||||
WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)
|
||||
`));
|
||||
stmts.push(this._stmt(`
|
||||
DELETE FROM groups WHERE id NOT IN (
|
||||
SELECT DISTINCT groupID FROM prefs WHERE groupID NOTNULL
|
||||
)
|
||||
`));
|
||||
|
||||
let prefs = new ContentPrefStore();
|
||||
|
||||
|
@ -451,38 +454,38 @@ ContentPrefService2.prototype = {
|
|||
// First get the matching prefs, then delete groups and prefs that reference
|
||||
// deleted groups.
|
||||
if (group) {
|
||||
stmts.push(this._stmtWithGroupClause(group, includeSubdomains, `
|
||||
SELECT groups.name AS grp, settings.name AS name
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
JOIN groups ON groups.id = prefs.groupID
|
||||
WHERE prefs.groupID IN (${GROUP_CLAUSE})
|
||||
`));
|
||||
stmts.push(this._stmtWithGroupClause(group, includeSubdomains,
|
||||
"SELECT groups.name AS grp, settings.name AS name",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"JOIN groups ON groups.id = prefs.groupID",
|
||||
"WHERE prefs.groupID IN ($)"
|
||||
));
|
||||
stmts.push(this._stmtWithGroupClause(group, includeSubdomains,
|
||||
"DELETE FROM groups WHERE id IN ($)"
|
||||
));
|
||||
stmts.push(this._stmt(
|
||||
"DELETE FROM prefs",
|
||||
"WHERE groupID NOTNULL AND groupID NOT IN (SELECT id FROM groups)"
|
||||
`DELETE FROM groups WHERE id IN (${GROUP_CLAUSE})`
|
||||
));
|
||||
stmts.push(this._stmt(`
|
||||
DELETE FROM prefs
|
||||
WHERE groupID NOTNULL AND groupID NOT IN (SELECT id FROM groups)
|
||||
`));
|
||||
}
|
||||
else {
|
||||
stmts.push(this._stmt(
|
||||
"SELECT NULL AS grp, settings.name AS name",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"WHERE prefs.groupID IS NULL"
|
||||
));
|
||||
stmts.push(this._stmt(`
|
||||
SELECT NULL AS grp, settings.name AS name
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
WHERE prefs.groupID IS NULL
|
||||
`));
|
||||
stmts.push(this._stmt(
|
||||
"DELETE FROM prefs WHERE groupID IS NULL"
|
||||
));
|
||||
}
|
||||
|
||||
// Finally delete settings that are no longer referenced.
|
||||
stmts.push(this._stmt(
|
||||
"DELETE FROM settings",
|
||||
"WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)"
|
||||
));
|
||||
stmts.push(this._stmt(`
|
||||
DELETE FROM settings
|
||||
WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)
|
||||
`));
|
||||
|
||||
let prefs = new ContentPrefStore();
|
||||
|
||||
|
@ -523,12 +526,12 @@ ContentPrefService2.prototype = {
|
|||
let stmts = [];
|
||||
|
||||
// First get the matching prefs.
|
||||
stmts.push(this._stmt(
|
||||
"SELECT groups.name AS grp, settings.name AS name",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"JOIN groups ON groups.id = prefs.groupID"
|
||||
));
|
||||
stmts.push(this._stmt(`
|
||||
SELECT groups.name AS grp, settings.name AS name
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
JOIN groups ON groups.id = prefs.groupID
|
||||
`));
|
||||
|
||||
stmts.push(this._stmt(
|
||||
"DELETE FROM prefs WHERE groupID NOTNULL"
|
||||
|
@ -536,10 +539,10 @@ ContentPrefService2.prototype = {
|
|||
stmts.push(this._stmt(
|
||||
"DELETE FROM groups"
|
||||
));
|
||||
stmts.push(this._stmt(
|
||||
"DELETE FROM settings",
|
||||
"WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)"
|
||||
));
|
||||
stmts.push(this._stmt(`
|
||||
DELETE FROM settings
|
||||
WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)
|
||||
`));
|
||||
|
||||
let prefs = new ContentPrefStore();
|
||||
|
||||
|
@ -585,21 +588,21 @@ ContentPrefService2.prototype = {
|
|||
|
||||
// First get the matching prefs. Include null if any of those prefs are
|
||||
// global.
|
||||
let stmt = this._stmt(
|
||||
"SELECT groups.name AS grp",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"JOIN groups ON groups.id = prefs.groupID",
|
||||
"WHERE settings.name = :name",
|
||||
"UNION",
|
||||
"SELECT NULL AS grp",
|
||||
"WHERE EXISTS (",
|
||||
"SELECT prefs.id",
|
||||
"FROM prefs",
|
||||
"JOIN settings ON settings.id = prefs.settingID",
|
||||
"WHERE settings.name = :name AND prefs.groupID IS NULL",
|
||||
")"
|
||||
);
|
||||
let stmt = this._stmt(`
|
||||
SELECT groups.name AS grp
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
JOIN groups ON groups.id = prefs.groupID
|
||||
WHERE settings.name = :name
|
||||
UNION
|
||||
SELECT NULL AS grp
|
||||
WHERE EXISTS (
|
||||
SELECT prefs.id
|
||||
FROM prefs
|
||||
JOIN settings ON settings.id = prefs.settingID
|
||||
WHERE settings.name = :name AND prefs.groupID IS NULL
|
||||
)
|
||||
`);
|
||||
stmt.params.name = name;
|
||||
stmts.push(stmt);
|
||||
|
||||
|
@ -614,11 +617,11 @@ ContentPrefService2.prototype = {
|
|||
stmts.push(this._stmt(
|
||||
"DELETE FROM prefs WHERE settingID NOT IN (SELECT id FROM settings)"
|
||||
));
|
||||
stmts.push(this._stmt(
|
||||
"DELETE FROM groups WHERE id NOT IN (",
|
||||
"SELECT DISTINCT groupID FROM prefs WHERE groupID NOTNULL",
|
||||
")"
|
||||
));
|
||||
stmts.push(this._stmt(`
|
||||
DELETE FROM groups WHERE id NOT IN (
|
||||
SELECT DISTINCT groupID FROM prefs WHERE groupID NOTNULL
|
||||
)
|
||||
`));
|
||||
|
||||
let prefs = new ContentPrefStore();
|
||||
|
||||
|
@ -660,14 +663,10 @@ ContentPrefService2.prototype = {
|
|||
* Returns the cached mozIStorageAsyncStatement for the given SQL. If no such
|
||||
* statement is cached, one is created and cached.
|
||||
*
|
||||
* @param sql The SQL query string. If more than one string is given, then
|
||||
* all are concatenated. The concatenation process inserts
|
||||
* spaces where appropriate and removes unnecessary contiguous
|
||||
* spaces. Call like _stmt("SELECT *", "FROM foo").
|
||||
* @param sql The SQL query string.
|
||||
* @return The cached, possibly new, statement.
|
||||
*/
|
||||
_stmt: function CPS2__stmt(sql1 /*, sql2, sql3, ... */) {
|
||||
let sql = joinArgs(arguments);
|
||||
_stmt: function CPS2__stmt(sql) {
|
||||
if (!this._statements)
|
||||
this._statements = {};
|
||||
if (!this._statements[sql])
|
||||
|
@ -805,7 +804,7 @@ ContentPrefService2.prototype = {
|
|||
cps._genericObservers = [];
|
||||
|
||||
let tables = ["prefs", "groups", "settings"];
|
||||
let stmts = tables.map(function (t) this._stmt("DELETE FROM", t), this);
|
||||
let stmts = tables.map(function (t) this._stmt(`DELETE FROM ${t}`), this);
|
||||
this._execStmts(stmts, { onDone: function () callback() });
|
||||
},
|
||||
|
||||
|
@ -848,7 +847,3 @@ function checkCallbackArg(callback, required) {
|
|||
function invalidArg(msg) {
|
||||
return Components.Exception(msg, Cr.NS_ERROR_INVALID_ARG);
|
||||
}
|
||||
|
||||
function joinArgs(args) {
|
||||
return Array.join(args, " ").trim().replace(/\s{2,}/g, " ");
|
||||
}
|
||||
|
|
|
@ -351,10 +351,10 @@ ContentPrefService.prototype = {
|
|||
try {
|
||||
this._dbConnection.executeSimpleSQL("DELETE FROM prefs WHERE groupID IS NOT NULL");
|
||||
this._dbConnection.executeSimpleSQL("DELETE FROM groups");
|
||||
this._dbConnection.executeSimpleSQL(
|
||||
"DELETE FROM settings " +
|
||||
"WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)"
|
||||
);
|
||||
this._dbConnection.executeSimpleSQL(`
|
||||
DELETE FROM settings
|
||||
WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)
|
||||
`);
|
||||
this._dbConnection.commitTransaction();
|
||||
}
|
||||
catch(ex) {
|
||||
|
@ -383,12 +383,12 @@ ContentPrefService.prototype = {
|
|||
if (!settingID)
|
||||
return;
|
||||
|
||||
var selectGroupsStmt = this._dbCreateStatement(
|
||||
"SELECT groups.id AS groupID, groups.name AS groupName " +
|
||||
"FROM prefs " +
|
||||
"JOIN groups ON prefs.groupID = groups.id " +
|
||||
"WHERE prefs.settingID = :setting "
|
||||
);
|
||||
var selectGroupsStmt = this._dbCreateStatement(`
|
||||
SELECT groups.id AS groupID, groups.name AS groupName
|
||||
FROM prefs
|
||||
JOIN groups ON prefs.groupID = groups.id
|
||||
WHERE prefs.settingID = :setting
|
||||
`);
|
||||
|
||||
var groupNames = [];
|
||||
var groupIDs = [];
|
||||
|
@ -573,14 +573,14 @@ ContentPrefService.prototype = {
|
|||
__stmtSelectPref: null,
|
||||
get _stmtSelectPref() {
|
||||
if (!this.__stmtSelectPref)
|
||||
this.__stmtSelectPref = this._dbCreateStatement(
|
||||
"SELECT prefs.value AS value " +
|
||||
"FROM prefs " +
|
||||
"JOIN groups ON prefs.groupID = groups.id " +
|
||||
"JOIN settings ON prefs.settingID = settings.id " +
|
||||
"WHERE groups.name = :group " +
|
||||
"AND settings.name = :setting"
|
||||
);
|
||||
this.__stmtSelectPref = this._dbCreateStatement(`
|
||||
SELECT prefs.value AS value
|
||||
FROM prefs
|
||||
JOIN groups ON prefs.groupID = groups.id
|
||||
JOIN settings ON prefs.settingID = settings.id
|
||||
WHERE groups.name = :group
|
||||
AND settings.name = :setting
|
||||
`);
|
||||
|
||||
return this.__stmtSelectPref;
|
||||
},
|
||||
|
@ -629,13 +629,13 @@ ContentPrefService.prototype = {
|
|||
__stmtSelectGlobalPref: null,
|
||||
get _stmtSelectGlobalPref() {
|
||||
if (!this.__stmtSelectGlobalPref)
|
||||
this.__stmtSelectGlobalPref = this._dbCreateStatement(
|
||||
"SELECT prefs.value AS value " +
|
||||
"FROM prefs " +
|
||||
"JOIN settings ON prefs.settingID = settings.id " +
|
||||
"WHERE prefs.groupID IS NULL " +
|
||||
"AND settings.name = :name"
|
||||
);
|
||||
this.__stmtSelectGlobalPref = this._dbCreateStatement(`
|
||||
SELECT prefs.value AS value
|
||||
FROM prefs
|
||||
JOIN settings ON prefs.settingID = settings.id
|
||||
WHERE prefs.groupID IS NULL
|
||||
AND settings.name = :name
|
||||
`);
|
||||
|
||||
return this.__stmtSelectGlobalPref;
|
||||
},
|
||||
|
@ -678,11 +678,11 @@ ContentPrefService.prototype = {
|
|||
__stmtSelectGroupID: null,
|
||||
get _stmtSelectGroupID() {
|
||||
if (!this.__stmtSelectGroupID)
|
||||
this.__stmtSelectGroupID = this._dbCreateStatement(
|
||||
"SELECT groups.id AS id " +
|
||||
"FROM groups " +
|
||||
"WHERE groups.name = :name "
|
||||
);
|
||||
this.__stmtSelectGroupID = this._dbCreateStatement(`
|
||||
SELECT groups.id AS id
|
||||
FROM groups
|
||||
WHERE groups.name = :name
|
||||
`);
|
||||
|
||||
return this.__stmtSelectGroupID;
|
||||
},
|
||||
|
@ -817,10 +817,10 @@ ContentPrefService.prototype = {
|
|||
__stmtInsertPref: null,
|
||||
get _stmtInsertPref() {
|
||||
if (!this.__stmtInsertPref)
|
||||
this.__stmtInsertPref = this._dbCreateStatement(
|
||||
"INSERT INTO prefs (groupID, settingID, value) " +
|
||||
"VALUES (:groupID, :settingID, :value)"
|
||||
);
|
||||
this.__stmtInsertPref = this._dbCreateStatement(`
|
||||
INSERT INTO prefs (groupID, settingID, value)
|
||||
VALUES (:groupID, :settingID, :value)
|
||||
`);
|
||||
|
||||
return this.__stmtInsertPref;
|
||||
},
|
||||
|
@ -867,10 +867,10 @@ ContentPrefService.prototype = {
|
|||
__stmtDeleteSettingIfUnused: null,
|
||||
get _stmtDeleteSettingIfUnused() {
|
||||
if (!this.__stmtDeleteSettingIfUnused)
|
||||
this.__stmtDeleteSettingIfUnused = this._dbCreateStatement(
|
||||
"DELETE FROM settings WHERE id = :id " +
|
||||
"AND id NOT IN (SELECT DISTINCT settingID FROM prefs)"
|
||||
);
|
||||
this.__stmtDeleteSettingIfUnused = this._dbCreateStatement(`
|
||||
DELETE FROM settings WHERE id = :id
|
||||
AND id NOT IN (SELECT DISTINCT settingID FROM prefs)
|
||||
`);
|
||||
|
||||
return this.__stmtDeleteSettingIfUnused;
|
||||
},
|
||||
|
@ -883,10 +883,10 @@ ContentPrefService.prototype = {
|
|||
__stmtDeleteGroupIfUnused: null,
|
||||
get _stmtDeleteGroupIfUnused() {
|
||||
if (!this.__stmtDeleteGroupIfUnused)
|
||||
this.__stmtDeleteGroupIfUnused = this._dbCreateStatement(
|
||||
"DELETE FROM groups WHERE id = :id " +
|
||||
"AND id NOT IN (SELECT DISTINCT groupID FROM prefs)"
|
||||
);
|
||||
this.__stmtDeleteGroupIfUnused = this._dbCreateStatement(`
|
||||
DELETE FROM groups WHERE id = :id
|
||||
AND id NOT IN (SELECT DISTINCT groupID FROM prefs)
|
||||
`);
|
||||
|
||||
return this.__stmtDeleteGroupIfUnused;
|
||||
},
|
||||
|
@ -899,13 +899,13 @@ ContentPrefService.prototype = {
|
|||
__stmtSelectPrefs: null,
|
||||
get _stmtSelectPrefs() {
|
||||
if (!this.__stmtSelectPrefs)
|
||||
this.__stmtSelectPrefs = this._dbCreateStatement(
|
||||
"SELECT settings.name AS name, prefs.value AS value " +
|
||||
"FROM prefs " +
|
||||
"JOIN groups ON prefs.groupID = groups.id " +
|
||||
"JOIN settings ON prefs.settingID = settings.id " +
|
||||
"WHERE groups.name = :group "
|
||||
);
|
||||
this.__stmtSelectPrefs = this._dbCreateStatement(`
|
||||
SELECT settings.name AS name, prefs.value AS value
|
||||
FROM prefs
|
||||
JOIN groups ON prefs.groupID = groups.id
|
||||
JOIN settings ON prefs.settingID = settings.id
|
||||
WHERE groups.name = :group
|
||||
`);
|
||||
|
||||
return this.__stmtSelectPrefs;
|
||||
},
|
||||
|
@ -931,12 +931,12 @@ ContentPrefService.prototype = {
|
|||
__stmtSelectGlobalPrefs: null,
|
||||
get _stmtSelectGlobalPrefs() {
|
||||
if (!this.__stmtSelectGlobalPrefs)
|
||||
this.__stmtSelectGlobalPrefs = this._dbCreateStatement(
|
||||
"SELECT settings.name AS name, prefs.value AS value " +
|
||||
"FROM prefs " +
|
||||
"JOIN settings ON prefs.settingID = settings.id " +
|
||||
"WHERE prefs.groupID IS NULL"
|
||||
);
|
||||
this.__stmtSelectGlobalPrefs = this._dbCreateStatement(`
|
||||
SELECT settings.name AS name, prefs.value AS value
|
||||
FROM prefs
|
||||
JOIN settings ON prefs.settingID = settings.id
|
||||
WHERE prefs.groupID IS NULL
|
||||
`);
|
||||
|
||||
return this.__stmtSelectGlobalPrefs;
|
||||
},
|
||||
|
@ -960,13 +960,13 @@ ContentPrefService.prototype = {
|
|||
__stmtSelectPrefsByName: null,
|
||||
get _stmtSelectPrefsByName() {
|
||||
if (!this.__stmtSelectPrefsByName)
|
||||
this.__stmtSelectPrefsByName = this._dbCreateStatement(
|
||||
"SELECT groups.name AS groupName, prefs.value AS value " +
|
||||
"FROM prefs " +
|
||||
"JOIN groups ON prefs.groupID = groups.id " +
|
||||
"JOIN settings ON prefs.settingID = settings.id " +
|
||||
"WHERE settings.name = :setting "
|
||||
);
|
||||
this.__stmtSelectPrefsByName = this._dbCreateStatement(`
|
||||
SELECT groups.name AS groupName, prefs.value AS value
|
||||
FROM prefs
|
||||
JOIN groups ON prefs.groupID = groups.id
|
||||
JOIN settings ON prefs.settingID = settings.id
|
||||
WHERE settings.name = :setting
|
||||
`);
|
||||
|
||||
return this.__stmtSelectPrefsByName;
|
||||
},
|
||||
|
@ -1140,8 +1140,10 @@ ContentPrefService.prototype = {
|
|||
_dbCreateIndices: function ContentPrefService__dbCreateIndices(aDBConnection) {
|
||||
for (let name in this._dbSchema.indices) {
|
||||
let index = this._dbSchema.indices[name];
|
||||
let statement = "CREATE INDEX IF NOT EXISTS " + name + " ON " + index.table +
|
||||
"(" + index.columns.join(", ") + ")";
|
||||
let statement = `
|
||||
CREATE INDEX IF NOT EXISTS ${name} ON ${index.table}
|
||||
(${index.columns.join(", ")})
|
||||
`;
|
||||
aDBConnection.executeSimpleSQL(statement);
|
||||
}
|
||||
},
|
||||
|
@ -1195,10 +1197,10 @@ ContentPrefService.prototype = {
|
|||
_dbMigrate1To3: function ContentPrefService___dbMigrate1To3(aDBConnection) {
|
||||
aDBConnection.executeSimpleSQL("ALTER TABLE groups RENAME TO groupsOld");
|
||||
aDBConnection.createTable("groups", this._dbSchema.tables.groups);
|
||||
aDBConnection.executeSimpleSQL(
|
||||
"INSERT INTO groups (id, name) " +
|
||||
"SELECT id, name FROM groupsOld"
|
||||
);
|
||||
aDBConnection.executeSimpleSQL(`
|
||||
INSERT INTO groups (id, name)
|
||||
SELECT id, name FROM groupsOld
|
||||
`);
|
||||
|
||||
aDBConnection.executeSimpleSQL("DROP TABLE groupers");
|
||||
aDBConnection.executeSimpleSQL("DROP TABLE groupsOld");
|
||||
|
|
|
@ -147,8 +147,10 @@ function testGetCaches(uri, prefName) {
|
|||
insertSetting.execute();
|
||||
let settingId = cps.DBConnection.lastInsertRowID;
|
||||
|
||||
let insertPref = cps.DBConnection.createStatement("INSERT INTO prefs (groupID, settingID, value) " +
|
||||
"VALUES (:groupId, :settingId, :value)");
|
||||
let insertPref = cps.DBConnection.createStatement(`
|
||||
INSERT INTO prefs (groupID, settingID, value)
|
||||
VALUES (:groupId, :settingId, :value)
|
||||
`);
|
||||
insertPref.params.groupId = groupId;
|
||||
insertPref.params.settingId = settingId;
|
||||
insertPref.params.value = VALUE;
|
||||
|
|
|
@ -30,10 +30,10 @@ function run_test() {
|
|||
}
|
||||
|
||||
function checkForUnusedGroups() {
|
||||
var stmt = cps.DBConnection.createStatement(
|
||||
"SELECT COUNT(*) AS count FROM groups " +
|
||||
"WHERE id NOT IN (SELECT DISTINCT groupID FROM prefs)"
|
||||
);
|
||||
var stmt = cps.DBConnection.createStatement(`
|
||||
SELECT COUNT(*) AS count FROM groups
|
||||
WHERE id NOT IN (SELECT DISTINCT groupID FROM prefs)
|
||||
`);
|
||||
stmt.executeStep();
|
||||
do_check_eq(0, stmt.row.count);
|
||||
stmt.reset();
|
||||
|
@ -41,10 +41,10 @@ function checkForUnusedGroups() {
|
|||
}
|
||||
|
||||
function checkForUnusedSettings() {
|
||||
var stmt = cps.DBConnection.createStatement(
|
||||
"SELECT COUNT(*) AS count FROM settings " +
|
||||
"WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)"
|
||||
);
|
||||
var stmt = cps.DBConnection.createStatement(`
|
||||
SELECT COUNT(*) AS count FROM settings
|
||||
WHERE id NOT IN (SELECT DISTINCT settingID FROM prefs)
|
||||
`);
|
||||
stmt.executeStep();
|
||||
do_check_eq(0, stmt.row.count);
|
||||
stmt.reset();
|
||||
|
|
|
@ -235,34 +235,36 @@ function arraysOfArraysOK(actual, expected, cmp) {
|
|||
|
||||
function dbOK(expectedRows) {
|
||||
let db = sendMessage("db");
|
||||
let stmt = db.createAsyncStatement(
|
||||
"SELECT groups.name AS grp, settings.name AS name, prefs.value AS value " +
|
||||
"FROM prefs " +
|
||||
"LEFT JOIN groups ON groups.id = prefs.groupID " +
|
||||
"LEFT JOIN settings ON settings.id = prefs.settingID " +
|
||||
"UNION " +
|
||||
let stmt = db.createAsyncStatement(`
|
||||
SELECT groups.name AS grp, settings.name AS name, prefs.value AS value
|
||||
FROM prefs
|
||||
LEFT JOIN groups ON groups.id = prefs.groupID
|
||||
LEFT JOIN settings ON settings.id = prefs.settingID
|
||||
UNION
|
||||
|
||||
// These second two SELECTs get the rows of the groups and settings tables
|
||||
// that aren't referenced by the prefs table. Neither should return any
|
||||
// rows if the component is working properly.
|
||||
"SELECT groups.name AS grp, NULL AS name, NULL AS value " +
|
||||
"FROM groups " +
|
||||
"WHERE id NOT IN (" +
|
||||
"SELECT DISTINCT groupID " +
|
||||
"FROM prefs " +
|
||||
"WHERE groupID NOTNULL" +
|
||||
") " +
|
||||
"UNION " +
|
||||
"SELECT NULL AS grp, settings.name AS name, NULL AS value " +
|
||||
"FROM settings " +
|
||||
"WHERE id NOT IN (" +
|
||||
"SELECT DISTINCT settingID " +
|
||||
"FROM prefs " +
|
||||
"WHERE settingID NOTNULL" +
|
||||
") " +
|
||||
/*
|
||||
These second two SELECTs get the rows of the groups and settings tables
|
||||
that aren't referenced by the prefs table. Neither should return any
|
||||
rows if the component is working properly.
|
||||
*/
|
||||
SELECT groups.name AS grp, NULL AS name, NULL AS value
|
||||
FROM groups
|
||||
WHERE id NOT IN (
|
||||
SELECT DISTINCT groupID
|
||||
FROM prefs
|
||||
WHERE groupID NOTNULL
|
||||
)
|
||||
UNION
|
||||
SELECT NULL AS grp, settings.name AS name, NULL AS value
|
||||
FROM settings
|
||||
WHERE id NOT IN (
|
||||
SELECT DISTINCT settingID
|
||||
FROM prefs
|
||||
WHERE settingID NOTNULL
|
||||
)
|
||||
|
||||
"ORDER BY value ASC, grp ASC, name ASC"
|
||||
);
|
||||
ORDER BY value ASC, grp ASC, name ASC
|
||||
`);
|
||||
|
||||
let actualRows = [];
|
||||
let cols = ["grp", "name", "value"];
|
||||
|
|
Загрузка…
Ссылка в новой задаче