Merge remote-tracking branch 'origin/dev'

This commit is contained in:
echel0n 2014-06-22 18:53:45 -07:00
commit 5500e0b245
2 changed files with 18 additions and 6 deletions

View file

@ -79,13 +79,16 @@ 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()
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

View file

@ -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.'