From 67a471a49d3e09d56400d6adf74c13af4c99aa7d Mon Sep 17 00:00:00 2001 From: SGCMarkus Date: Mon, 4 Mar 2024 11:33:05 +0100 Subject: [PATCH] astrodatagui: add StarsDB.py this class can only be instanciated once! --- astrodatagui/db/StarsDB.py | 40 +++++++++++++++++++++++++++++++++++++ astrodatagui/db/__init__.py | 0 2 files changed, 40 insertions(+) create mode 100644 astrodatagui/db/StarsDB.py create mode 100644 astrodatagui/db/__init__.py diff --git a/astrodatagui/db/StarsDB.py b/astrodatagui/db/StarsDB.py new file mode 100644 index 0000000..5dcfb66 --- /dev/null +++ b/astrodatagui/db/StarsDB.py @@ -0,0 +1,40 @@ +from enum import Enum +import sqlite3 + +class StarDBError(Enum): + NO_ERROR = 0 + DB_CONNECTION_FAILED = 1 + +DB_NAME = "stars.db" + +class StarDB(): + __instanceVar = None + + @staticmethod + def getInstance(): + if(StarDB.__instanceVar == None): + return StarDB() + else: + return StarDB.__instanceVar + + def __init__(self): + if(StarDB.__instanceVar != None): + raise Exception("StarDB cannot be instantiated more than once!") + else: + StarDB.__instanceVar = self + + self.error = StarDBError.NO_ERROR + + try: + con = sqlite3.connect(DB_NAME) + self.dbCursor = con.cursor() + except: + self.error = StarDBError.DB_CONNECTION_FAILED + + if(self.error is not StarDBError.NO_ERROR): + raise Exception("StarDB cannot connect to the database!") + else: + self.initializeDB() + + def initializeDB(self): + return \ No newline at end of file diff --git a/astrodatagui/db/__init__.py b/astrodatagui/db/__init__.py new file mode 100644 index 0000000..e69de29