From 8fe33dc91c2919f2b24474a037f6583824d920e7 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 12 Dec 2019 03:41:12 -0700 Subject: [PATCH] Fix loading of compressed global schema from DB on downgrade --- chrome/content/zotero/xpcom/db.js | 4 +++- chrome/content/zotero/xpcom/schema.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index e35a802587..e32aa46e86 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -580,7 +580,9 @@ Zotero.DBConnection.prototype.queryAsync = Zotero.Promise.coroutine(function* (s try { let onRow = null; let conn = this._getConnection(options) || (yield this._getConnectionAsync(options)); - [sql, params] = this.parseQueryAndParams(sql, params); + if (!options || !options.noParseParams) { + [sql, params] = this.parseQueryAndParams(sql, params); + } if (Zotero.Debug.enabled) { this.logQuery(sql, params, options); } diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index dd4a67dd79..f00acbc776 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -322,13 +322,12 @@ Zotero.Schema = new function(){ * Doesn't include the .itemTypes property, which was already applied to the mapping tables */ async function _readGlobalSchemaFromDB() { - var pako = {}; - Services.scriptloader.loadSubScript("resource://zotero/pako.js", pako); var data = await Zotero.DB.valueQueryAsync( "SELECT value FROM settings WHERE setting='globalSchema' AND key='data'" ); if (data) { try { + let pako = require('pako'); return JSON.parse(pako.inflate(data, { to: 'string' })); } catch (e) { @@ -360,7 +359,8 @@ Zotero.Schema = new function(){ var dbVersion = await Zotero.Schema.getDBVersion('globalSchema') || null; if (dbVersion > version) { - Zotero.debug(`Database has newer global schema (${dbVersion} > ${version}) -- skipping update`); + Zotero.debug(`Database has newer global schema (${dbVersion} > ${version}) ` + + `-- skipping update and using schema from DB`); return -1; } else if (dbVersion == version) { @@ -524,9 +524,12 @@ Zotero.Schema = new function(){ // Don't include types and fields, which are already in the mapping tables delete dbData.itemTypes; await Zotero.DB.queryAsync( - "REPLACE INTO settings VALUES ('globalSchema', 'data', ?)", - pako.deflate(JSON.stringify(dbData), { to: 'string' }), + "REPLACE INTO settings VALUES ('globalSchema', 'data', :data)", + { data: pako.deflate(JSON.stringify(dbData)) }, { + // Hack to pass named parameter to Sqlite.jsm, which in Fx60 treats an object passed + // as the the first parameter in a parameter array as an object of named parameters + noParseParams: true, debugParams: false } );