45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from .DbManager import DbManager
|
|
import json
|
|
import mariadb
|
|
|
|
|
|
class ContactDAO:
|
|
def __init__(self):
|
|
#print(f"*** File: {__file__}, __init__()")
|
|
self.__con = DbManager().getConnection()
|
|
if self.__con:
|
|
self.__cur = self.__con.cursor()
|
|
|
|
def getContacts(self):
|
|
print(f"*** File: {__file__}, getContacts()")
|
|
|
|
def addContact(self, contact, enc_key):
|
|
try:
|
|
if self.__cur:
|
|
self.__cur.callproc("addContactPerson", (enc_key, json.dumps(contact),))
|
|
self.__con.commit()
|
|
self.__cur.callproc("getLastInsertId")
|
|
contact_id = self.__cur.fetchone()
|
|
self.__cur.callproc("logger",(contact_id[0], "INSERT", "addContactPerson: New Contact added",))
|
|
self.__con.commit()
|
|
return contact_id[0]
|
|
else:
|
|
return None
|
|
except mariadb.Error as e:
|
|
print("MDB: " + str(e))
|
|
except Exception as e:
|
|
print("PYT: " + str(e))
|
|
|
|
def getContact(self, contact_id, enc_key = None):
|
|
try:
|
|
if self.__cur:
|
|
self.__cur.callproc("getCustomerContact", (contact_id, enc_key,))
|
|
#self.__all_cols = [desc[0] for desc in self.__cur.description]
|
|
return self.__cur.fetchall() #, self.__all_cols
|
|
else:
|
|
return None #, None
|
|
except mariadb.Error as e:
|
|
print(str(e))
|
|
|
|
|