use the new context Db connection class

use closing helper to auto close cousor when it goes out of context
This commit is contained in:
shaun 2016-11-05 10:20:09 +11:00
parent a763cd37c9
commit 4701041d99

View file

@ -9,6 +9,8 @@ import xbmc
import downloadutils import downloadutils
from utils import window, settings, kodiSQL from utils import window, settings, kodiSQL
from database import DatabaseConn
from contextlib import closing
################################################################################################# #################################################################################################
@ -102,24 +104,23 @@ class Read_EmbyServer():
viewId = view['Id'] viewId = view['Id']
# Compare to view table in emby database # Compare to view table in emby database
emby = kodiSQL('emby') with DatabaseConn('emby') as conn:
cursor_emby = emby.cursor() with closing(conn.cursor()) as cursor:
query = ' '.join(( query = ' '.join((
"SELECT view_name, media_type", "SELECT view_name, media_type",
"FROM view", "FROM view",
"WHERE view_id = ?" "WHERE view_id = ?"
)) ))
cursor_emby.execute(query, (viewId,)) cursor.execute(query, (viewId,))
result = cursor_emby.fetchone() result = cursor.fetchone()
try: try:
viewName = result[0] viewName = result[0]
mediatype = result[1] mediatype = result[1]
except TypeError: except TypeError:
viewName = None viewName = None
mediatype = None mediatype = None
cursor_emby.close()
return [viewName, viewId, mediatype] return [viewName, viewId, mediatype]