Use eraseByURI() instead of eraseByURIPrefix(), and fix params

This commit is contained in:
Dan Stillman 2013-01-29 04:03:56 -05:00
parent 56bb5b17ad
commit 7cd3479094
3 changed files with 16 additions and 7 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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);