From 0b20a629356d30086f59919a1c51a43b3ef79426 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 18 Oct 2009 16:03:54 +0000 Subject: [PATCH] Fix "constraint failed" error on "REPLACE INTO itemNotes" query when a standalone note in a collection becomes a child note remotely --- chrome/content/zotero/xpcom/data/item.js | 30 +++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index b1c857509..e68fbdf4b 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1687,20 +1687,34 @@ Zotero.Item.prototype.save = function() { + ' set to true in Item.save()'); } - sql = "REPLACE INTO itemNotes " - + "(itemID, sourceItemID, note, title) VALUES (?,?,?,?)"; var parent = this.isNote() ? this.getSource() : null; var noteText = this._noteText; // Add
wrapper if not present if (!noteText.match(/^
[\s\S]*<\/div>$/)) { noteText = '
' + noteText + '
'; } - var bindParams = [ - this.id, - parent ? parent : null, - noteText, - this._noteTitle - ]; + + var sql = "SELECT COUNT(*) FROM itemNotes WHERE itemID=?"; + if (Zotero.DB.valueQuery(sql, this.id)) { + sql = "UPDATE itemNotes SET sourceItemID=?, note=?, title=? WHERE itemID=?"; + var bindParams = [ + parent ? parent : null, + noteText, + this._noteTitle, + this.id + ]; + } + // Row might not yet exist for new embedded attachment notes + else { + sql = "INSERT INTO itemNotes " + + "(itemID, sourceItemID, note, title) VALUES (?,?,?,?)"; + var bindParams = [ + this.id, + parent ? parent : null, + noteText, + this._noteTitle + ]; + } Zotero.DB.query(sql, bindParams); }