diff --git a/chrome/content/zotero/xpcom/api.js b/chrome/content/zotero/xpcom/api.js index 6fffe78d9..f3aa9b040 100644 --- a/chrome/content/zotero/xpcom/api.js +++ b/chrome/content/zotero/xpcom/api.js @@ -96,17 +96,14 @@ Zotero.API = { s.addCondition('key', 'is', params.objectKey); } else if (params.objectID) { - Zotero.debug('adding ' + params.objectID); s.addCondition('itemID', 'is', params.objectID); } if (params.itemKey) { - s.addCondition('blockStart'); for (let i=0; i 1 + ? ` IN (${values.join(', ')})` + : `=${values[0]}`; } else { - condSQL += '=?'; + // Automatically cast values which might + // have been stored as integers + if (condition.value && typeof condition.value == 'string' + && condition.value.match(/^[1-9]+[0-9]*$/)) { + condSQL += ' LIKE ?'; + } + else if (condition.value === null) { + condSQL += ' IS NULL'; + break; + } + else { + condSQL += '=?'; + } + condSQLParams.push(condition['value']); } - condSQLParams.push(condition['value']); break; case 'beginsWith': diff --git a/chrome/content/zotero/xpcom/data/searchConditions.js b/chrome/content/zotero/xpcom/data/searchConditions.js index 91ff4ed5b..9eced1fb1 100644 --- a/chrome/content/zotero/xpcom/data/searchConditions.js +++ b/chrome/content/zotero/xpcom/data/searchConditions.js @@ -450,7 +450,17 @@ Zotero.SearchConditions = new function(){ table: 'items', field: 'key', special: true, - noLoad: true + noLoad: true, + inlineFilter: function (val) { + try { + val = Zotero.DataObjectUtilities.checkKey(val); + if (val) return `'${val}'`; + } + catch (e) { + Zotero.logError(e); + } + return false; + } }, { diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js index 030210782..42914b60a 100644 --- a/test/tests/searchTest.js +++ b/test/tests/searchTest.js @@ -224,6 +224,17 @@ describe("Zotero.Search", function() { }); }); + describe("key", function () { + it("should allow more than max bound parameters", function* () { + let s = new Zotero.Search(); + let max = Zotero.DB.MAX_BOUND_PARAMETERS + 100; + for (let i = 0; i < max; i++) { + s.addCondition('key', 'is', Zotero.DataObjectUtilities.generateKey()); + } + yield s.search(); + }); + }); + describe("savedSearch", function () { it("should return items in the saved search", function* () { var search = yield createDataObject('search');