From 92bf1255c432510f0c3b767d6c928e4e7e68de95 Mon Sep 17 00:00:00 2001 From: Ville-Pekka Vainio Date: Thu, 29 Jul 2010 22:58:13 +0300 Subject: [PATCH] minidb: Convert values in remove (RH bug 619295, gpo bug 1088) Make convert an instance method and convert the values in remove too. See also: RedHat bug 619295 and gPodder bug 1088 --- src/gpodder/minidb.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/gpodder/minidb.py b/src/gpodder/minidb.py index 6026c9f5..8c7ae53b 100644 --- a/src/gpodder/minidb.py +++ b/src/gpodder/minidb.py @@ -81,6 +81,12 @@ class Store(object): self.db.execute('CREATE TABLE %s (%s)' % (table, ', '.join('%s TEXT'%s for s in slots))) + def convert(self, v): + if isinstance(v, str) or isinstance(v, unicode): + return v + else: + return str(v) + def update(self, o, **kwargs): self.remove(o) for k, v in kwargs.items(): @@ -100,12 +106,7 @@ class Store(object): # Only save values that have values set (non-None values) slots = [s for s in slots if getattr(o, s, None) is not None] - def convert(v): - if isinstance(v, str) or isinstance(v, unicode): - return v - else: - return str(v) - values = [convert(getattr(o, slot)) for slot in slots] + values = [self.convert(getattr(o, slot)) for slot in slots] self.db.execute('INSERT INTO %s (%s) VALUES (%s)' % (table, ', '.join(slots), ', '.join('?'*len(slots))), values) @@ -135,7 +136,7 @@ class Store(object): # Use "None" as wildcard selector in remove actions slots = [s for s in slots if getattr(o, s, None) is not None] - values = [getattr(o, slot) for slot in slots] + values = [self.convert(getattr(o, slot)) for slot in slots] self.db.execute('DELETE FROM %s WHERE %s' % (table, ' AND '.join('%s=?'%s for s in slots)), values) -- 2.11.4.GIT