import xlrd
import pymysql
class Priority:
def __init__(self):
self.connection = pymysql.connect(host='localhost',
user='root',
password='123456',
db='skr_data_manage',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
def init_priority(self):
with self.connection.cursor() as cursor:
sql = "SELECT `id` FROM `ir_stand_question`"
cursor.execute(sql)
ret = cursor.fetchall()
stand_question_ids = [r['id'] for r in ret]
for stand_question_id in stand_question_ids:
sql = "SELECT `id` FROM `ir_stand_answer` WHERE `question_id`=%s"
cursor.execute(sql, (stand_question_id,))
ret = cursor.fetchall()
stand_answer_ids = [r['id'] for r in ret]
for index, stand_answer_id in enumerate(stand_answer_ids):
sql = "UPDATE `skr_data_manage`.`ir_stand_answer` SET priority=%s WHERE `id`=%s"
cursor.execute(sql, (index, stand_answer_id))
self.connection.commit()
self.connection.close()
priority = Priority()
priority.init_priority()
优雅的使用 pymysql
最新推荐文章于 2024-07-15 17:46:33 发布