def __update_schedule(self, json_data): conn_name = str(uuid.uuid4()) conn = access_manager.connect(conn_name) del_q = '''DELETE FROM schedule WHERE employee_id={i};'''\ .format(i=json_data['employee_id']) query = DBQuery(conn) query.begin_transaction() if not query.exec_query(del_q): print(query.get_error()) query.rollback_transaction() access_manager.disconnect(conn_name) return False schedule = json_data['schedule'] for s in schedule: str_query = self.__get_str_query_sched(s, json_data['employee_id']) if not query.exec_query(str_query): print(query.get_error()) query.rollback_transaction() access_manager.disconnect(conn_name) return False query.commit_transaction() access_manager.disconnect(conn_name) return True
def __update_position_in_db(self, json): conn_name = str(uuid.uuid4()) conn = access_manager.connect(conn_name) str_query = self.__get_str_query(json) sched_q = self.__get_str_query_sched(json) query = DBQuery(conn) query.begin_transaction() if not query.exec_query(str_query): print(query.get_error()) query.rollback_transaction() access_manager.disconnect(conn_name) return False if not query.exec_query(sched_q): print(query.get_error()) query.rollback_transaction() access_manager.disconnect(conn_name) return False query.commit_transaction() access_manager.disconnect(conn_name) return True
def __update_db(self, str_query: str): conn_name = str(uuid.uuid4()) conn = access_manager.connect(conn_name) query = DBQuery(conn) query.begin_transaction() if not query.exec_query(str_query): print(query.get_error()) query.rollback_transaction() access_manager.disconnect(conn_name) return False query.commit_transaction() access_manager.disconnect(conn_name) return True
def __insert_staff_to_db(self, json): conn_name = str(uuid.uuid4()) conn = access_manager.connect(conn_name) str_query_passport = self.__get_str_query_passport(json['passport']) query = DBQuery(conn) query.begin_transaction() if not query.exec_query(str_query_passport): print(query.get_error()) query.rollback_transaction() return False, None else: result = query.get_values() pass_id = str(result[0][0]) print(pass_id) str_query_staff = self.__get_str_query_staff(json, pass_id) if not query.exec_query(str_query_staff): print(query.get_error()) query.rollback_transaction() return False else: res = query.get_values() staff_id = str(res[0][0]) for sched_item in json['schedule']: str_query_sched = self.__get_str_query_sched(sched_item, staff_id) if not query.exec_query(str_query_sched): print(query.get_error()) query.rollback_transaction() return False query.commit_transaction() access_manager.disconnect(conn_name) return True
def __queryInsertDb(self, data: dict, owner: int): conn_name = str(uuid.uuid4()) conn = access_manager.connect(conn_name) query = DBQuery(conn) chip = data["chip_id"] query.begin_transaction() contract = data["contract"] chip = data["chip_id"] last_update_str = contract['last_update_date'] if len(last_update_str) == 0: last_update_str = 'NULL' else: last_update_str = "'{}'::date".format(last_update_str) str_query = '''INSERT INTO contract (code, conclusion_date, last_update_date, owner, valid_until) VALUES('{code}', '{conclusion_date}'::date, {last_update_date}, '{owner}', '{valid_until}'::date) RETURNING contr_id;'''.format( code=contract['code'], conclusion_date=contract['conclusion_date'], last_update_date=last_update_str, valid_until=contract['valid_until'], owner=owner) contr_id: int if not query.exec_query(str_query): query.rollback_transaction() print(query.get_error()) return False else: contr_id = query.get_values()[0][0] str_query = '''INSERT INTO microchips (chip_num, impl_date, country, location) VALUES('{chip_num}', '{impl_date}'::date, '{country}', '{location}') RETURNING chip_id;'''\ .format(chip_num=chip["chip_num"], impl_date=chip["impl_date"], country=chip["country"], location=chip["location"]) chip_id: int if not query.exec_query(str_query): query.rollback_transaction() print(query.get_error()) return False else: chip_id = query.get_values()[0][0] str_query = '''INSERT INTO animals_medical_records (name, breed, species, sex, castrated, birth, other_data, color, special_signs, registr_date, chip_id, contract, rel_path_to_photo) VALUES ('{name}', '{breed}', '{species}', '{sex}', '{castrated}', '{birth}'::date, '{other}', '{color}', '{special_signs}', '{registr_date}'::date, {chip_id}, {contract}, '{rel_path_to_photo}') RETURNING anim_id;'''\ .format(name=data["name"], breed=data["breed"], species=data["species"], sex=data["sex"], castrated=data["castrated"], birth=data["birth"], other=data["other_data"], color=data["color"], special_signs=data["special_signs"], registr_date=data["registr_date"], contract=contr_id, chip_id=chip_id, rel_path_to_photo=data["rel_path_to_photo"]) anim_id: int if not query.exec_query(str_query): query.rollback_transaction() print(query.get_error()) return False, 0 else: anim_id = query.get_values()[0][0] query.commit_transaction() access_manager.disconnect(conn_name) return True, anim_id
def __queryUpdateDb(self, data: dict): conn_name = str(uuid.uuid4()) conn = access_manager.connect(conn_name) query = DBQuery(conn) chip = data["chip_id"] query.begin_transaction() contract = data["contract"] chip = data["chip_id"] str_queries = [] last_update_str = contract['last_update_date'] if len(last_update_str) == 0: last_update_str = 'NULL' else: last_update_str = "'{}'::date".format(last_update_str) str_queries.append('''UPDATE animals_medical_records SET name='{name}', breed='{breed}',species='{species}', sex='{sex}', castrated='{castrated}', birth='{birth}'::date, other_data='{other}', color='{color}', special_signs='{special_signs}', registr_date='{registr_date}'::date, chip_id={chip_id}, contract={contract}, rel_path_to_photo='{rel_path_to_photo}' WHERE anim_id={anim_id};'''. format(anim_id=data["anim_id"], name=data["name"], breed=data["breed"], species=data["species"], sex=data["sex"], castrated=data["castrated"], birth=data["birth"], other=data["other_data"], color=data["color"], special_signs=data["special_signs"], registr_date=data["registr_date"], contract=contract["contr_id"], chip_id=chip["chip_id"], rel_path_to_photo=data["rel_path_to_photo"])) str_queries.append('''UPDATE contract SET code='{code}', conclusion_date='{conclusion_date}'::date, last_update_date={last_update_date}, valid_until='{valid_until}'::date WHERE contr_id={contr_id};''' .format(code=contract['code'], conclusion_date=contract['conclusion_date'], last_update_date=last_update_str, valid_until=contract['valid_until'], contr_id=contract['contr_id'])) str_queries.append('''UPDATE microchips SET chip_num='{chip_num}', impl_date='{impl_date}'::date, country='{country}', location='{location}' WHERE chip_id={chip_id}'''. format(chip_num=chip["chip_num"], impl_date=chip["impl_date"], country=chip["country"], location=chip["location"], chip_id=chip["chip_id"])) for str_query in str_queries: if not query.exec_query(str_query): query.rollback_transaction() print(query.get_error()) return False query.commit_transaction() access_manager.disconnect(conn_name) return True