From 576b9b7817a26691438d1c8560e42080cc77fb61 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 1 Sep 2021 06:19:56 -0400 Subject: [PATCH] Fix SQL error saving an item with hundreds of related items Fixes #2139 --- chrome/content/zotero/xpcom/data/dataObject.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index daf88df9fa..29470cc983 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -1102,10 +1102,16 @@ Zotero.DataObject.prototype._finalizeSave = Zotero.Promise.coroutine(function* ( toAdd[i][0] = yield Zotero.RelationPredicates.add(toAdd[i][0]); env.relationsToRegister.push([toAdd[i][0], toAdd[i][1]]); } - yield Zotero.DB.queryAsync( - sql + toAdd.map(x => "(?, ?, ?)").join(", "), - toAdd.map(x => [this.id, x[0], x[1]]) - .reduce((x, y) => x.concat(y)) + yield Zotero.Utilities.Internal.forEachChunkAsync( + toAdd, + Math.floor(Zotero.DB.MAX_BOUND_PARAMETERS / 3), + async function (chunk) { + await Zotero.DB.queryAsync( + sql + chunk.map(x => "(?, ?, ?)").join(", "), + chunk.map(x => [this.id, x[0], x[1]]) + .reduce((x, y) => x.concat(y)) + ); + }.bind(this) ); }