def test_prepare_update(self): sql, sql_tuple = prepare_update("users", {"email": "*****@*****.**"}, {"k1": "v1", "k2": "v2"}, ["k1", "k2", "k3"]) assert sql == 'UPDATE users SET k1 = ?,k2 = ? WHERE email = ?' assert sql_tuple == ("v1", "v2", "*****@*****.**") sql, sql_tuple = prepare_update("users", {"email": "*****@*****.**", "q1": 1000}, {"k1": "v1", "k2": "v2"}, ["k1"]) assert sql == 'UPDATE users SET k1 = ? WHERE email = ? and q1 = ?' assert sql_tuple == ("v1", "*****@*****.**", 1000)
def update(self, email, modify_obj): """ Modify user by the email account. :param email: :param modify_obj: modify object, keys are all optional. { name:?, pwd:? init_code:? user_type:?} :return: """ if len(self.query({"email": email})) == 0: return False if 'pwd' in modify_obj: crypted_pwd = UserService.hash_new_password(modify_obj['pwd']) modify_obj['pwd'] = crypted_pwd app.logger.debug( f"Update user:{email}, with modify_obj:{modify_obj}") sql, v_list = prepare_update( "users", {"email": email}, modify_obj, ['user_id', 'email', 'name', 'pwd', 'init_code', 'user_type']) app.logger.debug(f"sql:{sql}, value list:{v_list}") cur = self.sql_connection.cursor() cur.execute(sql, v_list) self.sql_connection.commit() # # debug: # self.query({'email': email}) return True
def update(self, update_condition, modify_obj): """ Modify user by the name or data_path . :param update_condition: {instance_id:''} and {text:''} :param modify_obj: modify object, keys are all optional.["instance_id", "label_type", "input_type", "text"] :return: """ if len(self.query(update_condition)) == 0: return False sql, v_tuple = prepare_update("label_candidates", update_condition, modify_obj, ["candidate_id", "instance_id", "label_type", "input_type", "text", "contour_label_value"]) cur = self.sql_connection.cursor() cur.execute(sql, v_tuple) self.sql_connection.commit() return True
def update(self, update_condition, modify_obj): """ Modify user by the name or data_path . :param update_condition: {name:''} or {data_path:''} :param modify_obj: modify object, keys are all optional. ['name', 'modality', 'description', 'data_path', 'has_audit', 'study_num', 'annotated_num'] :return: """ if len(self.query(update_condition)) == 0: return False sql, v_tuple = prepare_update("instances", update_condition, modify_obj, ['instance_id', 'name', 'modality', 'description', 'data_path', 'has_audit', 'study_num', 'annotated_num', "status"]) cur = self.sql_connection.cursor() cur.execute(sql, v_tuple) self.sql_connection.commit() return True
def update(self, update_condition, modify_obj): """ Modify studies by the name or data_path . :param update_condition: {study_id:''} or {instance_id:'', folder_name:''} :param modify_obj: modify object, keys are all optional. ['study_id', 'instance_id', 'folder_name', 'total_files_number', 'annotators', 'auditors'] :return: """ if len(self.query(update_condition)) == 0: return False sql, v_tuple = prepare_update("studies", update_condition, modify_obj, ['study_id', 'suid', 'patient_uid', 'study_uid', 'instance_id', 'folder_name', 'total_files_number', 'annotators', 'auditors', 'status']) cur = self.sql_connection.cursor() cur.execute(sql, v_tuple) self.sql_connection.commit() return True
def update(self, update_condition, modify_obj): """ Modify studies by the name or data_path . :param update_condition: {study_id:''} or {instance_id:'', folder_name:''} :param modify_obj: modify object, keys are all optional. ['study_id', 'instance_id', 'folder_name', 'total_files_number'] :return: """ if len(self.query(update_condition)) == 0: return False sql, v_tuple = prepare_update("series", update_condition, modify_obj, [ 'series_id', 'study_id', 'series_description', 'series_path', 'series_files_list', 'series_files_number', 'window_width', 'window_level', 'x_spacing', 'y_spacing', 'z_spacing', 'x_dimension', 'y_dimension', 'z_dimension', 'patient_id', 'series_instance_uid', 'study_date', 'intercept', 'slop', 'status' ]) cur = self.sql_connection.cursor() cur.execute(sql, v_tuple) self.sql_connection.commit() return True
def update(self, update_condition, modify_obj): """ Modify user by the name or data_path . :param update_condition: {instance_id:''} and {text:''} :param modify_obj: modify object, keys are all optional.["instance_id", "label_type", "input_type", "text"] :return: """ if len(self.query(update_condition)) == 0: return False sql, v_tuple = prepare_update("labels", update_condition, modify_obj, ["label_id", "candidate_id", "series_id", "user_id", "file_id", "content"]) cur = self.sql_connection.cursor() # print(f"Insert labels without commit!") try: cur.execute(sql, v_tuple) self.sql_connection.commit() except Exception: self.sql_connection.rollback() return False return True