#!/usr/bin/python
import pymysql
#选出非succeeded的task
#SELECT * FROM table_name WHERE XXXXX='' AND status!='SUCCEEDED'
#将某个task全部重置为CREATED
#update table_name set status = "CREATED" where XXXXX=''
#将pending重置为CREATED
#update table_name set status = "CREATED" where XXXXX='' and status='PENDING'
#将running重置为CREATED
#update table_name set status = "CREATED" where XXXXX='' and status='RUNNING'
#将failed重置为CREATED
#update table_name set status = "CREATED" where XXXXX='' and status='FAILED'
#python提示输入id
print("1、选出所有的非succeeded状态的子任务。2、将所有的非succeed状态的更新为created状态,3、将所有pending状态的更新为created,4、将所有的running状态额更新为created,5、将所有failed状态的更新为created。输入你想要的操作")
i = int(input())
print("你的输入是:",i)
#print(int(i))
if i == 1 :
conn = pymysql.connect(
host="XXXXX",
port=3306,
database='XXXXX',
charset='utf8',
user='XXXXX',
passwd='XXXXX'
)
try:
with conn.cursor() as cursor:
# sql = 'SELECT * FROM table_name LIMIT 3'
sql = "SELECT * FROM table_name WHERE XXXXX='1' AND status!='SUCCEEDED'"
cursor.execute(sql)
datas = cursor.fetchall()
# datas = cursor.fetchone()
# datas = cursor.fetchamany
print('获取的数据:\n', datas)
except Exception as e:
print("do nothing", e)
finally:
conn.close()
elif i == 2 :
conn = pymysql.connect(
host="XXXXX",
port=3306,
database='XXXXX',
charset='utf8',
user='XXXXX',
passwd='XXXXX'
)
try:
with conn.cursor() as cursor:
# sql = 'SELECT * FROM table_name LIMIT 3'
sql = "update table_name set status = \"FAILED\" where XXXXX='1'"
cursor.execute(sql)
conn.commit()
#datas = cursor.fetchall()
# datas = cursor.fetchone()
# datas = cursor.fetchamany
print('修改成功')
except Exception as e:
conn.rollback()
print("数据库操作异常:\n", e)
finally:
conn.close()
else:
print("nothing to do")
###################################
后续需要补充变量引入等等