Fix SQLite-related unicode encoding errors (bug 1465)

Python 3 cannot come fast enough.
This commit is contained in:
Thomas Perl 2011-10-29 20:41:42 +02:00
parent 76762fcabb
commit f03145a394
1 changed files with 14 additions and 1 deletions

View File

@ -202,7 +202,11 @@ class Database(object):
with self.lock:
try:
cur = self.cursor()
values = [getattr(o, name) for name in columns]
def convert(x):
if isinstance(x, str):
x = x.decode('utf-8', 'ignore')
return x
values = [convert(getattr(o, name)) for name in columns]
if o.id is None:
qmarks = ', '.join('?'*len(columns))
@ -244,6 +248,9 @@ class Database(object):
Returns True if a foldername for a channel exists.
False otherwise.
"""
if not isinstance(foldername, unicode):
foldername = foldername.decode('utf-8', 'ignore')
return self.get("SELECT id FROM %s WHERE download_folder = ?" % self.TABLE_PODCAST, (foldername,)) is not None
def episode_filename_exists(self, podcast_id, filename):
@ -251,6 +258,9 @@ class Database(object):
Returns True if a filename for an episode exists.
False otherwise.
"""
if not isinstance(filename, unicode):
filename = filename.decode('utf-8', 'ignore')
return self.get("SELECT id FROM %s WHERE podcast_id = ? AND download_filename = ?" % self.TABLE_EPISODE, (podcast_id, filename,)) is not None
def get_last_published(self, podcast):
@ -265,6 +275,9 @@ class Database(object):
a given channel. Used after feed updates for
episodes that have disappeared from the feed.
"""
if not isinstance(guid, unicode):
guid = guid.decode('utf-8', 'ignore')
with self.lock:
cur = self.cursor()
cur.execute('DELETE FROM %s WHERE podcast_id = ? AND guid = ?' % self.TABLE_EPISODE, \