From 643376769adac3de2531db6e56eabb60846eadaf Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 17 May 2009 07:52:05 +0000 Subject: [PATCH] =?UTF-8?q?Automatically=20hard-code=20NULL=20bound=20para?= =?UTF-8?q?meters=20(e.g.,=20convert=20"WHERE=20foo=3D=3F"=20to=20"WHERE?= =?UTF-8?q?=20foo=20IS=20NULL"=20and=20"SET=20foo=3D=3F"=20to=20"SET=20foo?= =?UTF-8?q?=3DNULL")?= --- chrome/content/zotero/xpcom/db.js | 80 ++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 12 deletions(-) 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