def _update(self): print('update') query = """UPDATE Deposits SET """ for key in Deposit.__dict__.keys(): if key[0] != '_' and key not in [ 'DepositeCode', 'load', 'save', 'delete' ]: param = key + '=' + '\'' + str(getattr(self, key)) + '\'' query += param query += ',' query = query[:-1] whereParam = """DepositeCode = """ + str(self.DepositeCode) query += """WHERE """ + whereParam print(query) DbInitializer.inst().ExecQuery(query)
def _update(self, entity): print('update') query = """UPDATE Currencies SET """ for key in Currency.__dict__.keys(): if key[0] != '_' and key not in [ 'CurrencyCode', 'load', 'save', 'delete' ]: param = key + '=' + '\'' + str(getattr(entity, key)) + '\'' query += param query += ',' query = query[:-1] whereParam = """CurrencyCode = """ + str(entity.CurrencyCode) query += """WHERE """ + whereParam print(query) DbInitializer.inst().ExecQuery(query)
def load(self, paramDict): query = """SELECT """ for key in Deposit.__dict__.keys(): if key[0] != '_' and key not in ['load', 'save', 'delete']: query += key query += ',' query = query[:-1] query += " FROM Deposits WHERE " equal_substr = '{attr_name} = {attr_value}' counter = len(paramDict) for param in paramDict: query += equal_substr.format(attr_name=param, attr_value=paramDict[param]) if counter == 1: query += ';' else: query += ' AND ' counter -= 1 print(query) resultRow = DbInitializer.inst().ExecAndReturn(query)[0] if resultRow is not None: attrCounter = 0 for key in Deposit.__dict__.keys(): if key[0] != '_' and key not in ['load', 'save', 'delete']: valueOfCell = str(resultRow[attrCounter]) setattr(self, key, valueOfCell) attrCounter += 1 else: print("Row is not exist")
def _update(self, instanceToUpdate): print('update') query = """UPDATE Employees SET """ for key in Employee.__dict__.keys(): if key[0] != '_' and key not in [ 'EmployeeCode', 'load', 'save', 'delete' ]: param = key + '=' + '\'' + str(getattr(instanceToUpdate, key)) + '\'' query += param query += ',' query = query[:-1] whereParam = """EmployeeCode = """ + str(instanceToUpdate.EmployeeCode) query += """WHERE """ + whereParam print(query) DbInitializer.inst().ExecQuery(query)
def save(self): print('insert') if self.DepositeCode == 0: query = """INSERT INTO Deposits (""" for key in Deposit.__dict__.keys(): if key[0] != '_' and key not in [ 'DepositeCode', 'load', 'save', 'delete' ]: query += key query += ',' query = query[:-1] query += """) VALUES (""" for key in Deposit.__dict__.keys(): if key[0] != '_' and key not in [ 'DepositeCode', 'load', 'save', 'delete' ]: query += '\'' + str(getattr(self, key)) + '\'' query += ',' query = query[:-1] query += ')' print(query) DbInitializer.inst().ExecQuery(query) else: self._update()
def save(self, instanceToSave): print('insert') if instanceToSave.EmployeeCode == 0: query = """INSERT INTO Employees (""" for key in Employee.__dict__.keys(): if key[0] != '_' and key not in [ 'EmployeeCode', 'load', 'save', 'delete' ]: query += key query += ',' query = query[:-1] query += """) VALUES (""" for key in Employee.__dict__.keys(): if key[0] != '_' and key not in [ 'EmployeeCode', 'load', 'save', 'delete' ]: query += '\'' + str(getattr(instanceToSave, key)) + '\'' query += ',' query = query[:-1] query += ')' print(query) DbInitializer.inst().ExecQuery(query) else: self._update(instanceToSave)
def save(self, entity): print('insert') if entity.RoleCode == 0: query = """INSERT INTO Roles (""" for key in Role.__dict__.keys(): if key[0] != '_' and key not in [ 'RoleCode', 'load', 'save', 'delete' ]: query += key query += ',' query = query[:-1] query += """) VALUES (""" for key in Role.__dict__.keys(): if key[0] != '_' and key not in [ 'RoleCode', 'load', 'save', 'delete' ]: query += '\'' + str(getattr(entity, key)) + '\'' query += ',' query = query[:-1] query += ')' print(query) DbInitializer.inst().ExecQuery(query) else: self._update(entity)
def getAll(self): query = """SELECT """ for key in Currency.__dict__.keys(): if key[0] != '_' and key not in ['load', 'save', 'delete']: query += key query += ',' query = query[:-1] query += " FROM Roles" print(query) resultRows = DbInitializer.inst().ExecAndReturn(query) if resultRows is not None: for resultRow in resultRows: attrCounter = 0 currentEntity = Role() for key in Role.__dict__.keys(): if key[0] != '_' and key not in ['load', 'save', 'delete']: valueOfCell = str(resultRow[attrCounter]) setattr(currentEntity, key, valueOfCell) attrCounter += 1 self.Entities.append(currentEntity) return self.Entities else: print("Rows is not exist")
def delete(self): print('delete') query = """DELETE FROM Deposits WHERE DepositeCode=""" query += str(self.DepositeCode) DbInitializer.inst().ExecQuery(query)
def delete(self): print('delete') query = """DELETE FROM Employees WHERE EmployeeCode=""" query += str(self.EmployeeCode) DbInitializer.inst().ExecQuery(query)
def delete(self): print('delete') query = """DELETE FROM Investors WHERE InvestorCode=""" query += str(self.InvestorCode) DbInitializer.inst().ExecQuery(query)
def delete(self): print('delete') query = """DELETE FROM Currencies WHERE CurrencyCode=""" query += str(self.CurrencyCode) DbInitializer.inst().ExecQuery(query)
def delete(self, entity): print('delete') query = """DELETE FROM Roles WHERE RoleCode=""" query += str(entity.RoleCode) DbInitializer.inst().ExecQuery(query)
from BankDomain.Investor import Investor from BankDomain.Currency import Currency from BankDomain.Deposits import Deposit from BankDomain.Role import Role from BankDomain.Employee import Employee from BankDomain.BankUOW import domainUOW from BankDomain.DBInitializer import DbInitializer from BankDomain.DAOs import EmployeeDAO initializer = DbInitializer.inst() initializer.CreateTables() #initializer.CreateTables(); uow = domainUOW() empDAO = EmployeeDAO() inst = Employee() inst.EmployeeCode = 20 inst.Pib = 'Kosobutskiy Bogdan' inst.PassportData = 'Tu354352' inst.Address = "Jitomir st." inst.Age = 23 inst.RoleCode = 3 #uow.registerNew(inst) #empDAO.save(inst); insert = Employee() insert.RoleCode = 2 insert.Pib = 'Lazuto Maxim' insert.PassportData = 'MK233433' insert.Address = 'Kyiv'