diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index ecfa72dc1..aa2083ec1 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -286,20 +286,22 @@ Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env) env.parent ? env.parent : null ); - if (isNew) { - env.sqlColumns.unshift('collectionID'); - env.sqlValues.unshift(collectionID ? { int: collectionID } : null); - - let placeholders = env.sqlColumns.map(() => '?').join(); - let sql = "INSERT INTO collections (" + env.sqlColumns.join(', ') + ") " - + "VALUES (" + placeholders + ")"; - yield Zotero.DB.queryAsync(sql, env.sqlValues); - } - else { - let sql = 'UPDATE collections SET ' - + env.sqlColumns.map(x => x + '=?').join(', ') + ' WHERE collectionID=?'; - env.sqlValues.push(collectionID ? { int: collectionID } : null); - yield Zotero.DB.queryAsync(sql, env.sqlValues); + if (env.sqlColumns.length) { + if (isNew) { + env.sqlColumns.unshift('collectionID'); + env.sqlValues.unshift(collectionID ? { int: collectionID } : null); + + let placeholders = env.sqlColumns.map(() => '?').join(); + let sql = "INSERT INTO collections (" + env.sqlColumns.join(', ') + ") " + + "VALUES (" + placeholders + ")"; + yield Zotero.DB.queryAsync(sql, env.sqlValues); + } + else { + let sql = 'UPDATE collections SET ' + + env.sqlColumns.map(x => x + '=?').join(', ') + ' WHERE collectionID=?'; + env.sqlValues.push(collectionID ? { int: collectionID } : null); + yield Zotero.DB.queryAsync(sql, env.sqlValues); + } } if (this._changed.parentKey) { diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index c62509898..8b3400371 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -959,7 +959,7 @@ Zotero.DataObject.prototype._saveData = function (env) { env.sqlValues.push(0); } - if (env.isNew || !env.options.skipClientDateModified) { + if (env.isNew || !env.options.skipClientDateModifiedUpdate) { env.sqlColumns.push('clientDateModified'); env.sqlValues.push(Zotero.DB.transactionDateTime); } diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 82a7a897c..944eacc5d 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1268,28 +1268,30 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { env.sqlValues.push(this.dateModified); } - if (isNew) { - env.sqlColumns.push('dateAdded'); - env.sqlValues.push(this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime); - - env.sqlColumns.unshift('itemID'); - env.sqlValues.unshift(parseInt(itemID)); - - let sql = "INSERT INTO items (" + env.sqlColumns.join(", ") + ") " - + "VALUES (" + env.sqlValues.map(() => "?").join() + ")"; - yield Zotero.DB.queryAsync(sql, env.sqlValues); - - if (!env.options.skipNotifier) { - Zotero.Notifier.queue('add', 'item', itemID, env.notifierData, env.options.notifierQueue); + if (env.sqlColumns.length) { + if (isNew) { + env.sqlColumns.push('dateAdded'); + env.sqlValues.push(this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime); + + env.sqlColumns.unshift('itemID'); + env.sqlValues.unshift(parseInt(itemID)); + + let sql = "INSERT INTO items (" + env.sqlColumns.join(", ") + ") " + + "VALUES (" + env.sqlValues.map(() => "?").join() + ")"; + yield Zotero.DB.queryAsync(sql, env.sqlValues); + + if (!env.options.skipNotifier) { + Zotero.Notifier.queue('add', 'item', itemID, env.notifierData, env.options.notifierQueue); + } } - } - else { - let sql = "UPDATE items SET " + env.sqlColumns.join("=?, ") + "=? WHERE itemID=?"; - env.sqlValues.push(parseInt(itemID)); - yield Zotero.DB.queryAsync(sql, env.sqlValues); - - if (!env.options.skipNotifier) { - Zotero.Notifier.queue('modify', 'item', itemID, env.notifierData, env.options.notifierQueue); + else { + let sql = "UPDATE items SET " + env.sqlColumns.join("=?, ") + "=? WHERE itemID=?"; + env.sqlValues.push(parseInt(itemID)); + yield Zotero.DB.queryAsync(sql, env.sqlValues); + + if (!env.options.skipNotifier) { + Zotero.Notifier.queue('modify', 'item', itemID, env.notifierData, env.options.notifierQueue); + } } } diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index 5d917a42f..aaa953600 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -171,20 +171,22 @@ Zotero.Search.prototype._saveData = Zotero.Promise.coroutine(function* (env) { { string: this.name } ); - if (isNew) { - env.sqlColumns.unshift('savedSearchID'); - env.sqlValues.unshift(searchID ? { int: searchID } : null); - - let placeholders = env.sqlColumns.map(() => '?').join(); - let sql = "INSERT INTO savedSearches (" + env.sqlColumns.join(', ') + ") " - + "VALUES (" + placeholders + ")"; - yield Zotero.DB.queryAsync(sql, env.sqlValues); - } - else { - let sql = 'UPDATE savedSearches SET ' - + env.sqlColumns.map(x => x + '=?').join(', ') + ' WHERE savedSearchID=?'; - env.sqlValues.push(searchID ? { int: searchID } : null); - yield Zotero.DB.queryAsync(sql, env.sqlValues); + if (env.sqlColumns.length) { + if (isNew) { + env.sqlColumns.unshift('savedSearchID'); + env.sqlValues.unshift(searchID ? { int: searchID } : null); + + let placeholders = env.sqlColumns.map(() => '?').join(); + let sql = "INSERT INTO savedSearches (" + env.sqlColumns.join(', ') + ") " + + "VALUES (" + placeholders + ")"; + yield Zotero.DB.queryAsync(sql, env.sqlValues); + } + else { + let sql = 'UPDATE savedSearches SET ' + + env.sqlColumns.map(x => x + '=?').join(', ') + ' WHERE savedSearchID=?'; + env.sqlValues.push(searchID ? { int: searchID } : null); + yield Zotero.DB.queryAsync(sql, env.sqlValues); + } } if (this._changed.conditions) {