def update_by_template(self, template, new_values): """ :param template: Template for rows to match. :param new_values: New values to set for matching fields. :return: Number of rows updated. """ cox = pymysql.connect(**self.connect_info) sql, args = SQLHelper.create_update(self.table_name, new_values, template) num, res = SQLHelper.run_q(sql, args, conn=cox) return num
def update_by_key(self, key_fields, new_values): """ :param key_fields: List of value for the key fields. :param new_values: A dict of field:value to set for updated row. :return: Number of rows updated. """ cox = pymysql.connect(**self.connect_info) template = dict(zip(self.key_columns, key_fields)) sql, args = SQLHelper.create_update(self.table_name, new_values, template) num, res = SQLHelper.run_q(sql, args, cox) return num
def update_by_template(self, template, new_values): """ :param template: Template for rows to match. :param new_values: New values to set for matching fields. :return: Number of rows updated. """ sql, args = SQLHelper.create_update(table_name=self.table_name, template=template, new_values=new_values) res, data = SQLHelper.run_q(sql=sql, args=args, conn=self.connect_info, commit=self.commit) return res
def update_by_key(self, key_fields, new_values): """ :param key_fields: List of value for the key fields. :param new_values: A dict of field:value to set for updated row. :return: Number of rows updated. """ template = {k: v for k, v in zip(self.key_columns, key_fields)} sql, args = SQLHelper.create_update(table_name=self.table_name, template=template, new_values=new_values) res, data = SQLHelper.run_q(sql=sql, args=args, conn=self.connect_info, commit=self.commit) return res