StarsDB: add close function
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user