From 517e945266b505a0e52e992583f970e4b0aade4c Mon Sep 17 00:00:00 2001 From: simonmicro Date: Sat, 6 Dec 2025 18:59:08 +0100 Subject: [PATCH] Cleanup Signed-off-by: simonmicro --- py-kms/pykms_Sql.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/py-kms/pykms_Sql.py b/py-kms/pykms_Sql.py index 841c557..3ed7bfd 100644 --- a/py-kms/pykms_Sql.py +++ b/py-kms/pykms_Sql.py @@ -20,18 +20,12 @@ def sql_initialize(dbName): if not os.path.isfile(dbName): # Initialize the database. loggersrv.debug(f'Initializing database file "{dbName}"...') - con = None try: - con = sqlite3.connect(dbName) - cur = con.cursor() - cur.execute("CREATE TABLE clients(clientMachineId TEXT , machineName TEXT, applicationId TEXT, skuId TEXT, licenseStatus TEXT, lastRequestTime INTEGER, kmsEpid TEXT, requestCount INTEGER, PRIMARY KEY(clientMachineId, applicationId))") - + with sqlite3.connect(dbName) as con: + cur = con.cursor() + cur.execute("CREATE TABLE clients(clientMachineId TEXT, machineName TEXT, applicationId TEXT, skuId TEXT, licenseStatus TEXT, lastRequestTime INTEGER, kmsEpid TEXT, requestCount INTEGER, PRIMARY KEY(clientMachineId, applicationId))") except sqlite3.Error as e: pretty_printer(log_obj = loggersrv.error, to_exit = True, put_text = "{reverse}{red}{bold}Sqlite Error: %s. Exiting...{end}" %str(e)) - finally: - if con: - con.commit() - con.close() def sql_get_all(dbName): if not os.path.isfile(dbName):