diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index b310912c68..b7801d4d8d 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -213,6 +213,65 @@ Zotero.DBConnection.prototype.columnQuery = function (sql,params) { Zotero.DBConnection.prototype.getStatement = function (sql, params, checkParams) { var db = this._getDBConnection(); + // First, determine the type of query using first word + var matches = sql.match(/^[^\s\(]*/); + queryMethod = matches[0].toLowerCase(); + + if (params) { + // If single scalar value or single non-array object, wrap in an array + if (typeof params != 'object' || params === null || + (params && typeof params == 'object' && !params.length)) { + var params = [params]; + } + + // Since we might make changes, only work on a copy of the array + var params = params.concat(); + + // Replace NULL bound parameters with hard-coded NULLs + var nullRE = /\s*=?\s*\?/g; + // Reset lastIndex, since regexp isn't recompiled dynamically + nullRE.lastIndex = 0; + var lastNullParamIndex = -1; + for (var i=0; i