From 4701041d99cb64361a15bcaa2e31d6b9a7865e9a Mon Sep 17 00:00:00 2001 From: shaun Date: Sat, 5 Nov 2016 10:20:09 +1100 Subject: [PATCH] use the new context Db connection class use closing helper to auto close cousor when it goes out of context --- resources/lib/read_embyserver.py | 33 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/resources/lib/read_embyserver.py b/resources/lib/read_embyserver.py index 57ef4337..5ea9cafa 100644 --- a/resources/lib/read_embyserver.py +++ b/resources/lib/read_embyserver.py @@ -9,6 +9,8 @@ import xbmc import downloadutils from utils import window, settings, kodiSQL +from database import DatabaseConn +from contextlib import closing ################################################################################################# @@ -102,24 +104,23 @@ class Read_EmbyServer(): viewId = view['Id'] # Compare to view table in emby database - emby = kodiSQL('emby') - cursor_emby = emby.cursor() - query = ' '.join(( + with DatabaseConn('emby') as conn: + with closing(conn.cursor()) as cursor: + query = ' '.join(( - "SELECT view_name, media_type", - "FROM view", - "WHERE view_id = ?" - )) - cursor_emby.execute(query, (viewId,)) - result = cursor_emby.fetchone() - try: - viewName = result[0] - mediatype = result[1] - except TypeError: - viewName = None - mediatype = None + "SELECT view_name, media_type", + "FROM view", + "WHERE view_id = ?" + )) + cursor.execute(query, (viewId,)) + result = cursor.fetchone() + try: + viewName = result[0] + mediatype = result[1] + except TypeError: + viewName = None + mediatype = None - cursor_emby.close() return [viewName, viewId, mediatype]