From 0d6faa8f6ea2c202ac570cb9ad60f75aed036ed1 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 17 Feb 2018 14:02:11 -0800 Subject: [PATCH] Take advantage of new sql_update to update where_keys. --- etiquette/objects.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index 23e6ed4..c2950fc 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -125,10 +125,11 @@ class GroupableMixin: ) else: # Since this group was a child, its parent adopts all its children. - cur.execute( - 'UPDATE %s SET parentid == ? WHERE parentid == ?' % self.group_table, - [parent.id, self.id] - ) + data = { + 'parentid': (self.id, parent.id), + } + self.photodb.sql_update(table=self.group_table, pairs=data, where_key='parentid') + # Note that this part comes after the deletion of children to prevent # issues of recursion. cur.execute( @@ -1009,11 +1010,10 @@ class Photo(ObjectBase): except OSError: spinal.copy_file(old_path, new_path) - cur = self.photodb.sql.cursor() - cur.execute( - 'UPDATE photos SET filepath = ? WHERE filepath == ?', - [new_path.absolute_path, old_path.absolute_path] - ) + data = { + 'filepath': (old_path.absolute_path, new_path.absolute_path), + } + self.photodb.sql_update(table='photos', pairs=data, where_key='filepath') if new_path.normcase == old_path.normcase: # If they are equivalent but differently cased, just rename. @@ -1127,14 +1127,15 @@ class Tag(ObjectBase, GroupableMixin): # Migrate the old tag's synonyms to the new one # UPDATE is safe for this operation because there is no chance of duplicates. self.photodb._cached_frozen_children = None - cur = self.photodb.sql.cursor() - cur.execute( - 'UPDATE tag_synonyms SET mastername = ? WHERE mastername == ?', - [mastertag.name, self.name] - ) + + data = { + 'mastername': (self.name, mastertag.name), + } + self.photodb.sql_update(table='tag_synonyms', pairs=data, where_key='mastername') # Iterate over all photos with the old tag, and swap them to the new tag # if they don't already have it. + cur = self.photodb.sql.cursor() cur.execute('SELECT photoid FROM photo_tag_rel WHERE tagid == ?', [self.id]) fetches = cur.fetchall() @@ -1301,12 +1302,11 @@ class Tag(ObjectBase, GroupableMixin): } self.photodb.sql_update(table='tags', pairs=data, where_key='id') - cur = self.photodb.sql.cursor() if apply_to_synonyms: - cur.execute( - 'UPDATE tag_synonyms SET mastername = ? WHERE mastername = ?', - [new_name, old_name] - ) + data = { + 'mastername': (old_name, new_name), + } + self.photodb.sql_update(table='tag_synonyms', pairs=data, where_key='mastername') self.name = new_name self._uncache()