【发布时间】:2022-01-09 06:27:43
【问题描述】:
所以我有“time_estimations_4”表,我想在其中更新“Mod_on”表上的值
问题: 保留 Mod_on 列 0 而不是将其更新为 1
额外信息: 打印出来没有
创建表如下:
sql = '''CREATE TABLE IF NOT EXISTS time_estimation_4(
turn BIGINT primary key auto_increment,
Mod_on int DEFAULT 0,
mod_id BIGINT,
mods_online BIGINT
)'''
这里是更新:
@pro.command()
async def online(ctx):
sql_check_user = f'''SELECT mod_id FROM time_estimation_4 WHERE mod_id = {ctx.author.id}'''
cur.execute(sql_check_user)
out_user = cur.fetchone()
user = ctx.author.id
if out_user == None:
cur.execute('INSERT INTO time_estimation_4 (mod_id) VALUES (%s)', (user,))
db.commit()
sql1 = f'''SELECT Mod_on FROM time_estimation_4 WHERE mod_id = {ctx.author.id}'''
cur.execute(sql)
out = cur.fetchone()
print(out)
if out == 1:
await ctx.send("mod's already online")
elif out == 0:
sql2 = f'''UPDATE time_estimation_4 SET Mod_on = 1 WHERE mod_id = {ctx.author.id}'''
await ctx.send("Done! You won't be recieving notifications and time estimation will be longer!" )
有人看到可能的问题吗?
【问题讨论】:
标签: python mysql sql discord discord.py