diff --git a/ordigi/collection.py b/ordigi/collection.py index b3a0ae4..44d7ebb 100644 --- a/ordigi/collection.py +++ b/ordigi/collection.py @@ -287,7 +287,6 @@ class Collection(object): row_data = {} for title in self.db.tables[table]['header']: key = utils.camel2snake(title) - # Convert Path type to str row_data[title] = metadata[key] return row_data @@ -336,6 +335,10 @@ class Collection(object): media.metadata['file_path'] = os.path.relpath(dest_path, self.root) self._add_db_data(dest_path, media.metadata) + if self.mode == 'move': + # Delete file path entry in db when file is moved inside collection + if str(self.root) in str(src_path): + self.db.delete_filepath(str(src_path.relative_to(self.root))) self.summary.append((src_path, dest_path)) record = True diff --git a/ordigi/database.py b/ordigi/database.py index b057e08..414d1b6 100644 --- a/ordigi/database.py +++ b/ordigi/database.py @@ -259,17 +259,20 @@ class Sqlite: return value - def delete_row(self, table, id): + def delete_row(self, table, column, value): """ Delete a row by row id in table :param table: database table :param id: id of the row :return: """ - sql = f'delete from {table} where id=?' - self.cur.execute(sql, (id,)) + sql = f'delete from {table} where {column}=?' + self.cur.execute(sql, (value,)) self.con.commit() + def delete_filepath(self, value): + self.delete_row('metadata', 'FilePath', value) + def delete_all_rows(self, table): """ Delete all row in table