From a58b644062c443f4d6a15cb28db5e87c80608e7e Mon Sep 17 00:00:00 2001
From: shaun <shaun@bluebit.com.au>
Date: Sat, 5 Nov 2016 11:51:17 +1100
Subject: [PATCH] use the new DatabaseCon context class use closing with for
 cursor

---
 resources/lib/context_entry.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/resources/lib/context_entry.py b/resources/lib/context_entry.py
index 882b0489..d7a7bf0c 100644
--- a/resources/lib/context_entry.py
+++ b/resources/lib/context_entry.py
@@ -13,6 +13,8 @@ import embydb_functions as embydb
 import musicutils as musicutils
 from utils import settings, dialog, language as lang, kodiSQL
 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:
 
-            conn = kodiSQL('emby')
-            cursor = conn.cursor()
-            emby_db = embydb.Embydb_Functions(cursor)
-            item = emby_db.getItem_byKodiId(kodi_id, item_type)
-            cursor.close()
-            try:
-                item_id = item[0]
-            except TypeError:
-                pass
+            with DatabaseConn('emby') as conn:
+                with closing(conn.cursor()) as cursor:            
+                    emby_db = embydb.Embydb_Functions(cursor)
+                    item = emby_db.getItem_byKodiId(kodi_id, item_type)
+                    try:
+                        item_id = item[0]
+                    except TypeError:
+                        pass
 
         return item_id