From 7cd3479094e6f05a52e8ccc3c0d8ccb7a7d17563 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 29 Jan 2013 04:03:56 -0500 Subject: [PATCH] Use eraseByURI() instead of eraseByURIPrefix(), and fix params --- .../content/zotero/xpcom/data/collection.js | 2 +- chrome/content/zotero/xpcom/data/item.js | 2 +- chrome/content/zotero/xpcom/data/relations.js | 19 ++++++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index 95fefa2f7c..e257bc97b9 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -966,7 +966,7 @@ Zotero.Collection.prototype.erase = function(deleteItems) { // Remove relations var uri = Zotero.URI.getCollectionURI(this); - Zotero.Relations.eraseByURIPrefix(uri); + Zotero.Relations.eraseByURI(uri); var placeholders = collections.map(function () '?').join(); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 39673ad2a8..b4ca880bd3 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -4170,7 +4170,7 @@ Zotero.Item.prototype.erase = function() { // Remove relations (except for merge tracker) var uri = Zotero.URI.getItemURI(this); - Zotero.Relations.eraseByURIPrefix(uri, [Zotero.Relations.deletedItemPredicate]); + Zotero.Relations.eraseByURI(uri, [Zotero.Relations.deletedItemPredicate]); Zotero.DB.query('DELETE FROM annotations WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM highlights WHERE itemID=?', this.id); diff --git a/chrome/content/zotero/xpcom/data/relations.js b/chrome/content/zotero/xpcom/data/relations.js index 5324890739..be26ba280b 100644 --- a/chrome/content/zotero/xpcom/data/relations.js +++ b/chrome/content/zotero/xpcom/data/relations.js @@ -185,8 +185,10 @@ Zotero.Relations = new function () { var sql = "SELECT ROWID FROM relations WHERE (subject LIKE ? OR object LIKE ?)"; var params = [prefix, prefix]; if (ignorePredicates) { - sql += " AND predicate != ?"; - params = params.concat(ignorePredicates); + for each(var ignorePredicate in ignorePredicates) { + sql += " AND predicate != ?"; + params.push(ignorePredicate); + } } var ids = Zotero.DB.columnQuery(sql, params); @@ -199,11 +201,18 @@ Zotero.Relations = new function () { } - this.eraseByURI = function (uri) { + this.eraseByURI = function (uri, ignorePredicates) { Zotero.DB.beginTransaction(); - var sql = "SELECT ROWID FROM relations WHERE subject=? OR object=?"; - var ids = Zotero.DB.columnQuery(sql, [uri, uri]); + var sql = "SELECT ROWID FROM relations WHERE (subject=? OR object=?)"; + var params = [uri, uri]; + if (ignorePredicates) { + for each(var ignorePredicate in ignorePredicates) { + sql += " AND predicate != ?"; + params.push(ignorePredicate); + } + } + var ids = Zotero.DB.columnQuery(sql, params); for each(var id in ids) { var relation = this.get(id);