StarsDB: add close function

This commit is contained in:
2024-03-04 12:25:06 +01:00
parent 11e3d88cba
commit 4c458203d7
+6
View File
@@ -26,6 +26,7 @@ class StarDB():
if(dbName in StarDB.__dbNames): if(dbName in StarDB.__dbNames):
raise Exception(f"StarDB {dbName} cannot be instantiated more than once!") raise Exception(f"StarDB {dbName} cannot be instantiated more than once!")
else: else:
self.dbName = dbName
StarDB.__dbNames.append(dbName) StarDB.__dbNames.append(dbName)
StarDB.__instances.append(self) StarDB.__instances.append(self)
@@ -42,6 +43,11 @@ class StarDB():
else: else:
self.initializeDB() self.initializeDB()
def close(self):
StarDB.__instances.remove(self)
StarDB.__dbNames.remove(self.dbName)
self.connection.close()
def initializeDB(self): def initializeDB(self):
print("Initializing database") print("Initializing database")
self.dbCursor.execute("""CREATE TABLE IF NOT EXISTS starnames self.dbCursor.execute("""CREATE TABLE IF NOT EXISTS starnames