no existance checks

This commit is contained in:
josch 2012-07-01 14:29:04 +02:00
parent b55097e8c3
commit 1c80c2d97d
2 changed files with 23 additions and 20 deletions

View file

@ -514,11 +514,11 @@ class EntryTree(Gtk.TreeView):
self.feedurl = None
for feedurl in config:
if self.feeddb.feed_exists(feedurl):
if self.feeddb.get_feed(feedurl):
self.update(feedurl)
def display(self, feedurl):
if not feedurl or not self.feeddb.feed_exists(feedurl):
if not feedurl or not self.feeddb.get_feed(feedurl):
self.set_model(self.empty_model)
self.feedurl = None
else:
@ -605,8 +605,8 @@ class FeedTree(Gtk.TreeView):
for category, feeds in categories.items():
it = self.model.append(None, [None, category, folder_icon, None])
for feedurl in feeds:
if self.feeddb.feed_exists(feedurl):
feed = self.feeddb.get_feed(feedurl)
if feed:
feed_icon = feed.get('favicon')
if feed_icon:
feed_icon = pixbuf_new_from_file_in_memory(feed_icon, (16, 16))
@ -822,7 +822,7 @@ class FeedTree(Gtk.TreeView):
# TODO: display error "cannot identify feeditems"
break
if self.feeddb.entry_exists(feedurl, itemid):
if self.feeddb.get_entry(feedurl, itemid):
# already exists
continue

View file

@ -54,18 +54,27 @@ class SQLStorage():
dbcreate(self.conn)
def get_feed(self, feed):
return dict(zip(('title', 'favicon', 'etag', 'lastmodified', 'unread'),
self.conn.execute("""SELECT title, favicon, etag, lastmodified, unread FROM feeds WHERE feed=?""", (feed,)).fetchone()))
result = self.conn.execute("""SELECT title, favicon, etag, lastmodified, unread FROM feeds WHERE feed=?""", (feed,)).fetchone()
if result:
return dict(zip(('title', 'favicon', 'etag', 'lastmodified', 'unread'), result))
else:
return dict()
def get_entry(self, feed, entry):
return dict(zip(('title', 'content', 'link', 'date', 'unread', 'categories'),
self.conn.execute("""SELECT title, content, link, date, unread, categories FROM entries WHERE feed=? AND entry=?""", (feed, entry)).fetchone()))
result = self.conn.execute("""SELECT title, content, link, date, unread, categories FROM entries WHERE feed=? AND entry=?""", (feed, entry)).fetchone()
if result:
return dict(zip(('title', 'content', 'link', 'date', 'unread', 'categories'), result))
else:
return dict()
def get_entries_all(self, feed):
return [dict(zip(('entry', 'title', 'date', 'unread'), content))
for content in self.conn.execute("""
SELECT entry, title, date, unread FROM entries WHERE feed=? ORDER BY date DESC
""", (feed,)).fetchall()]
result = self.conn.execute(
"""SELECT entry, title, date, unread FROM entries WHERE feed=? ORDER BY date DESC""",
(feed,)).fetchall()
if result:
return [dict(zip(('entry', 'title', 'date', 'unread'), c)) for c in result]
else:
return list()
def add_entry(self, feed, entry, values):
self.conn.execute("""REPLACE INTO entries (feed, entry, title, content, link, date, unread, categories) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
@ -74,7 +83,7 @@ class SQLStorage():
def update_feed(self, feed, values):
self.conn.execute("""UPDATE feeds SET title=?, favicon=?, etag=?, lastmodified=?, unread=? WHERE feed=?""",
(values['title'], values['favicon'], values['etag'], values['lastmodified'], values['unread'], feed))
(values['title'], values.get('favicon'), values.get('etag'), values.get('lastmodified'), values['unread'], feed))
self.conn.commit()
def set_favicon(self, feed, favicon):
@ -91,12 +100,6 @@ class SQLStorage():
self.conn.execute("""UPDATE feeds set unread=0 WHERE feed=?""", (feed,))
self.conn.commit()
def feed_exists(self, feed):
return self.conn.execute("""SELECT feed FROM feeds WHERE feed=?""", (feed,)).fetchone() is not None
def entry_exists(self, feed, entry):
return self.conn.execute("""SELECT feed FROM entries WHERE feed=? AND entry=?""", (feed,entry)).fetchone() is not None
def close(self):
self.conn.close()