From f6c40d4b251706a84df34886f8de10f0d9b3b711 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 22 Jun 2014 18:52:46 -0700 Subject: [PATCH] Fixed DB issues related to displaying plot details for show episodes. --- sickbeard/db.py | 20 ++++++++++++++++---- sickbeard/webserve.py | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/sickbeard/db.py b/sickbeard/db.py index 2097d2d3..cb2ecada 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -79,14 +79,17 @@ class DBConnection(object): if self.connection is None: self.reconnect() return self.connection.cursor() - def execute(self, query, args=None, fetchall=False): + def execute(self, query, args=None, fetchall=False, fetchone=False): """Executes the given query, returning the lastrowid from the query.""" cursor = self._cursor() try: if fetchall: return self._execute(cursor, query, args).fetchall() - return self._execute(cursor, query, args) + elif fetchone: + return self._execute(cursor, query, args).fetchone() + else: + return self._execute(cursor, query, args) finally: cursor.close() @@ -165,7 +168,7 @@ class DBConnection(object): return sqlResult - def action(self, query, args=None, fetchall=False): + def action(self, query, args=None, fetchall=False, fetchone=False): with db_lock: @@ -182,7 +185,7 @@ class DBConnection(object): else: logger.log(self.filename + ": " + query + " with args " + str(args), logger.DB) - sqlResult = self.execute(query, args, fetchall=fetchall) + sqlResult = self.execute(query, args, fetchall=fetchall, fetchone=fetchone) # get out of the connection attempt loop since we were successful break @@ -209,6 +212,15 @@ class DBConnection(object): return sqlResults + def selectOne(self, query, args=None): + + sqlResults = self.action(query, args, fetchone=True) + + if sqlResults == None: + return [] + + return sqlResults + def upsert(self, tableName, valueDict, keyDict): changesBefore = self.connection.total_changes diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 9d66bc8f..5df8ff27 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -3479,9 +3479,9 @@ class Home(MainHandler): def plotDetails(self, show, season, episode): myDB = db.DBConnection() - result = myDB.action( + result = myDB.selectOne( "SELECT description FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?", - (int(show), int(season), int(episode))).fetchone() + (int(show), int(season), int(episode))) return result['description'] if result else 'Episode not found.'