www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 0b20a629356d30086f59919a1c51a43b3ef79426
parent 66fbf3d0085e00f74243cae1fccae3647d7be7e6
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sun, 18 Oct 2009 16:03:54 +0000

Fix "constraint failed" error on "REPLACE INTO itemNotes" query when a standalone note in a collection becomes a child note remotely


Diffstat:
Mchrome/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 @@ -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 <div> wrapper if not present if (!noteText.match(/^<div class="zotero-note znv[0-9]+">[\s\S]*<\/div>$/)) { noteText = '<div class="zotero-note znv1">' + noteText + '</div>'; } - 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); }