use the new DatabaseCon context class

use closing with for cursor
This commit is contained in:
shaun 2016-11-05 11:51:17 +11:00
parent b3214a9250
commit a58b644062

View file

@ -13,6 +13,8 @@ import embydb_functions as embydb
import musicutils as musicutils import musicutils as musicutils
from utils import settings, dialog, language as lang, kodiSQL from utils import settings, dialog, language as lang, kodiSQL
from dialogs import context from dialogs import context
from database import DatabaseConn
from contextlib import closing
################################################################################################# #################################################################################################
@ -87,15 +89,14 @@ class ContextMenu(object):
if not item_id and kodi_id and item_type: if not item_id and kodi_id and item_type:
conn = kodiSQL('emby') with DatabaseConn('emby') as conn:
cursor = conn.cursor() with closing(conn.cursor()) as cursor:
emby_db = embydb.Embydb_Functions(cursor) emby_db = embydb.Embydb_Functions(cursor)
item = emby_db.getItem_byKodiId(kodi_id, item_type) item = emby_db.getItem_byKodiId(kodi_id, item_type)
cursor.close() try:
try: item_id = item[0]
item_id = item[0] except TypeError:
except TypeError: pass
pass
return item_id return item_id