def replace_episode(self, feed: Feed, episode: Episode) -> None: """Replace (or insert) an episode in the database. This method is used for both updating an episode and for adding a new one. Episode instances have an ep_id field which is the episode's unique id in the database, if set. If it was not set when this method is called, we update it after the episode has been added to the database. Args: feed: the Feed the episode is a part of episode: the Episode to replace """ cursor = self._conn.cursor() if episode.ep_id is None: cursor.execute(self.SQL_EPISODE_REPLACE_NOID, (episode.title, feed.key, episode.description, episode.link, episode.pubdate, episode.copyright, episode.enclosure, episode.played)) episode.ep_id = cursor.lastrowid else: cursor.execute( self.SQL_EPISODE_REPLACE, (episode.ep_id, episode.title, feed.key, episode.description, episode.link, episode.pubdate, episode.copyright, episode.enclosure, episode.played)) self._conn.commit()
def replace_episode(self, feed: Feed, episode: Episode) -> None: cursor = self._conn.cursor() if episode.ep_id is None: sql = "replace into episode (title, feed_key, description, link, pubdate, copyright, enclosure, played)\n" \ "values (?,?,?,?,?,?,?,?)" cursor.execute(sql, ( episode.title, feed.key, episode.description, episode.link, episode.pubdate, episode.copyright, episode.enclosure, episode.played )) episode.ep_id = cursor.lastrowid else: sql = "replace into episode (id, title, feed_key, description, link, pubdate, copyright, enclosure, played)\n" \ "values (?,?,?,?,?,?,?,?,?)" cursor.execute(sql, ( episode.ep_id, episode.title, feed.key, episode.description, episode.link, episode.pubdate, episode.copyright, episode.enclosure, episode.played )) self._conn.commit()