Skip to content

Commit

Permalink
minidb: Convert values in remove (RH bug 619295, gpo bug 1088)
Browse files Browse the repository at this point in the history
Make convert an instance method and
convert the values in remove too.

See also:
RedHat bug 619295 and gPodder bug 1088
  • Loading branch information
Ville-Pekka Vainio authored and thp committed Aug 20, 2010
1 parent 6a2c1ba commit 92bf125
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/gpodder/minidb.py
Expand Up @@ -81,6 +81,12 @@ def _register(self, class_):
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():
Expand All @@ -100,12 +106,7 @@ def save(self, o):
# 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)

Expand Down Expand Up @@ -135,7 +136,7 @@ def remove(self, o):
# 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)

Expand Down

0 comments on commit 92bf125

Please sign in to comment.