astrodatagui: add StarsDB.py
this class can only be instanciated once!
This commit is contained in:
@@ -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
|
||||||
Reference in New Issue
Block a user