43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from .DbManager import DbManager
|
|
import json
|
|
import mariadb
|
|
from PySide6.QtCore import QObject, Signal
|
|
from ..PyqcrmFlags import PyqcrmAppliEmpyFlags
|
|
|
|
|
|
class ObjectDAO(QObject):
|
|
newObjectAdded = Signal(bool, int)
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
#print(f"*** File: {__file__}, __init__()")
|
|
self.__con = DbManager().getConnection()
|
|
if self.__con:
|
|
self.__cur = self.__con.cursor()
|
|
|
|
def addObject(self, new_object):
|
|
try:
|
|
if self.__cur:
|
|
self.__cur.callproc("addObject", (json.dumps(new_object),))
|
|
self.__con.commit()
|
|
self.__cur.callproc("getLastInsertId")
|
|
object_id = self.__cur.fetchone()
|
|
self.newObjectAdded.emit(True, object_id[0])
|
|
return object_id[0]
|
|
else:
|
|
return None
|
|
except mariadb.Error as e:
|
|
self.newObjectAdded.emit(False)
|
|
print(str(e))
|
|
|
|
def getObjects(self, criterion, enc_key = None):
|
|
try:
|
|
if self.__cur:
|
|
self.__cur.callproc("getObjects", (criterion, 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))
|