Added start blocke on no database connection available
This commit is contained in:
@@ -4,9 +4,12 @@ import json
|
||||
|
||||
|
||||
class AddressDAO:
|
||||
__cur = None
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, init()")
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__cur = self.__con.cursor()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
|
||||
def __importPlz(self):
|
||||
@@ -29,6 +32,9 @@ class AddressDAO:
|
||||
print("FINISHED")#
|
||||
|
||||
def getAddressData(self, all = True, zipcode = None):
|
||||
self.__cur.callproc("getAddress", (all, zipcode,))
|
||||
self.__data = self.__cur.fetchall()
|
||||
return self.__data
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getAddress", (all, zipcode,))
|
||||
self.__data = self.__cur.fetchall()
|
||||
return self.__data
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -2,11 +2,17 @@ from .DbManager import DbManager
|
||||
|
||||
|
||||
class BTypeDAO:
|
||||
__cur = None
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, init()")
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__cur = self.__con.cursor()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def getBType(self):
|
||||
self.__cur.callproc("getBtype", (None, None, ))
|
||||
data = self.__cur.fetchall()
|
||||
return(data)
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getBtype", (None, None, ))
|
||||
data = self.__cur.fetchall()
|
||||
return(data)
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -6,21 +6,30 @@ from PySide6.QtCore import QObject, Signal
|
||||
|
||||
class BusinessDAO(QObject):
|
||||
newBusinessAdded = Signal()
|
||||
|
||||
__cur = None
|
||||
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, init()")
|
||||
super().__init__()
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__cur = self.__con.cursor()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def getBusiness(self, enc_key, criterion = "Alle"):
|
||||
self.__cur.callproc("getCustomerView", (enc_key, criterion,))
|
||||
self.__all_cols = [desc[0] for desc in self.__cur.description]
|
||||
return self.__cur.fetchall(), self.__all_cols
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getCustomerView", (enc_key, criterion,))
|
||||
self.__all_cols = [desc[0] for desc in self.__cur.description]
|
||||
return self.__cur.fetchall(), self.__all_cols
|
||||
else:
|
||||
return None, None
|
||||
|
||||
def addBusiness(self, data, contact_id):
|
||||
try:
|
||||
self.__cur.callproc("addBusiness", (json.dumps(data), contact_id))
|
||||
self.__con.commit()
|
||||
self.newBusinessAdded.emit()
|
||||
if self.__cur:
|
||||
self.__cur.callproc("addBusiness", (json.dumps(data), contact_id))
|
||||
self.__con.commit()
|
||||
self.newBusinessAdded.emit()
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(str(e))
|
||||
|
||||
@@ -113,7 +113,7 @@ class BusinessModel(QAbstractTableModel):
|
||||
|
||||
@Slot(int)
|
||||
def onRowClicked(self, row):
|
||||
print(row)
|
||||
print(f"Selected table row: {row}, corresponding DB ID: {self.__data[row][0]}")
|
||||
|
||||
@Slot(str)
|
||||
def viewCriterion(self, criterion):
|
||||
|
||||
@@ -7,18 +7,22 @@ class ContactDAO:
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, __init__()")
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__cur = self.__con.cursor()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def getContacts(self):
|
||||
print(f"*** File: {__file__}, getContacts()")
|
||||
|
||||
def addContact(self, contact, enc_key):
|
||||
try:
|
||||
self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),))
|
||||
self.__con.commit()
|
||||
self.__cur.callproc("getLastInsertId")
|
||||
contact_id = self.__cur.fetchone()
|
||||
return contact_id[0]
|
||||
if self.__cur:
|
||||
self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),))
|
||||
self.__con.commit()
|
||||
self.__cur.callproc("getLastInsertId")
|
||||
contact_id = self.__cur.fetchone()
|
||||
return contact_id[0]
|
||||
else:
|
||||
return None
|
||||
except mariadb.Error as e:
|
||||
print("MDB: " + str(e))
|
||||
except Exception as e:
|
||||
|
||||
@@ -7,10 +7,10 @@ class ContactModel(QObject):
|
||||
contactIdReady = Signal(int)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# print(f"*** File: {__file__}, __init__()")
|
||||
#self.logger = logging.getLogger()
|
||||
self.__conf = ConfigLoader().getConfig()
|
||||
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
|
||||
#self.logger = logging.getLogger()
|
||||
# print(f"*** File: {__file__}, __init__()")
|
||||
self.__data = self.__getData()
|
||||
|
||||
def getContacts(self):
|
||||
|
||||
@@ -16,14 +16,17 @@ class DbManager(object):
|
||||
|
||||
|
||||
def getConnection(cls):
|
||||
#print(f"DB Manager: {cls.__dbmanager}")
|
||||
#print(f"DB Connection: {cls.__connection}")
|
||||
try:
|
||||
if not cls.__connection or not cls.__connection.ping():
|
||||
cls.__failure_notified = False
|
||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||
except mariadb.InterfaceError as e:
|
||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||
print(f"DbManager Connection (INTERFACE ERROR): {e}..reconnecting...")
|
||||
except mariadb.Error as e:
|
||||
print(f"Connection parameters are wrong: {e}")
|
||||
print(f"File: {__file__}\n Database connection error: {e}")
|
||||
cls.__connection = None
|
||||
|
||||
return cls.__connection
|
||||
|
||||
@@ -4,15 +4,20 @@ from ..PyqcrmFlags import PyqcrmFlags
|
||||
import mariadb
|
||||
|
||||
class UserDAO:
|
||||
__cursor = None
|
||||
def __init__(self):
|
||||
#print(f"*** File: {__file__}, init()")
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__cur = self.__con.cursor()
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
|
||||
def createUser(self, username, password, info, role= PyqcrmFlags.USER):
|
||||
user_created = True
|
||||
user_created = False
|
||||
try:
|
||||
self.__cur.callproc("createUser", (username, password, info, role))
|
||||
self.__con.commit()
|
||||
if self.__cur:
|
||||
self.__cur.callproc("createUser", (username, password, info, role))
|
||||
self.__con.commit()
|
||||
user_created = True
|
||||
except mariadb.Error as e:
|
||||
print(f"Error: {e}")
|
||||
print(e.errno)
|
||||
@@ -21,8 +26,11 @@ class UserDAO:
|
||||
return user_created
|
||||
|
||||
def getUser(self, username):
|
||||
self.__cur.callproc("getUser", (username,))
|
||||
return self.__cur.fetchone()
|
||||
if self.__cur:
|
||||
self.__cur.callproc("getUser", (username,))
|
||||
return self.__cur.fetchone()
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,13 +13,14 @@ class UserManager(QObject):
|
||||
def __init__(self, user_config = None, role = None):
|
||||
super().__init__()
|
||||
self.__con = DbManager().getConnection()
|
||||
self.__cur = self.__con.cursor()
|
||||
if user_config and role:
|
||||
if self.__con:
|
||||
self.__cur = self.__con.cursor()
|
||||
if user_config and role:
|
||||
|
||||
self.__username = user_config["PYQCRM_USER"]
|
||||
self.__password = user_config["PYQCRM_USER_PASS"]
|
||||
self.__info = user_config["PYQCRM_USER_INFO"]
|
||||
self.__role = role if role == PyqcrmFlags.ADMIN else 0
|
||||
self.__username = user_config["PYQCRM_USER"]
|
||||
self.__password = user_config["PYQCRM_USER_PASS"]
|
||||
self.__info = user_config["PYQCRM_USER_INFO"]
|
||||
self.__role = role if role == PyqcrmFlags.ADMIN else 0
|
||||
|
||||
|
||||
def createUser(self):
|
||||
|
||||
Reference in New Issue
Block a user