diff --git a/sickbeard/db.py b/sickbeard/db.py index a324a745..5dfca35c 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -115,7 +115,7 @@ class DBConnection: with db_lock: # remove None types - querylist = [i for i in querylist if i!=None] + querylist = [i for i in querylist if i != None] if querylist == None: return @@ -125,7 +125,7 @@ class DBConnection: # Transaction self.connection.isolation_level = None - self.connection.execute('begin') + self.connection.execute('BEGIN') while attempt < 5: try: @@ -140,7 +140,7 @@ class DBConnection: logger.log(qu[0] + " with args " + str(qu[1]), logger.DEBUG) sqlResult.append(self.connection.execute(qu[0], qu[1])) - self.connection.execute('commit') + self.connection.execute('COMMIT') logger.log(u"Transaction with " + str(len(querylist)) + u" queries executed", logger.DEBUG) return sqlResult @@ -240,6 +240,9 @@ class DBConnection: d[col[0]] = row[idx] return d + def hasTable(self, tableName): + return len(self.action("SELECT 1 FROM sqlite_master WHERE name = ?;", (tableName, )).fetchall()) > 0 + def sanityCheckDatabase(connection, sanity_check): sanity_check(connection).check() diff --git a/sickbeard/name_cache.py b/sickbeard/name_cache.py index a39e5192..c47046a9 100644 --- a/sickbeard/name_cache.py +++ b/sickbeard/name_cache.py @@ -45,11 +45,14 @@ def retrieveNameFromCache(name): Returns: the TVDB and TVRAGE id that resulted from the cache lookup or None if the show wasn't found in the cache """ + cache_results = None + # standardize the name we're using to account for small differences in providers name = sanitizeSceneName(name) cacheDB = db.DBConnection('cache.db') - cache_results = cacheDB.select("SELECT * FROM scene_names WHERE name = ?", [name]) + if cacheDB.hasTable('scene_names'): + cache_results = cacheDB.select("SELECT * FROM scene_names WHERE name = ?", [name]) if cache_results: return int(cache_results[0]["indexer_id"])