【发布时间】:2019-08-28 20:10:29
【问题描述】:
我有一个不和谐的机器人,它将接受一些用户输入并将其作为一行插入 mysql。数据已经过验证,但 mysql 库拒绝将其作为行插入。如果我让它打印命令而不是发送它,然后从 mysql 主机执行它,它插入就好了。
async def addsourceserver(ctx, name=None, description=None, ip=None, port=None, query_port=None):
mydb = msc(ctx.guild.id)
mycursor = mydb.cursor(buffered=True)
try:
# Checking if the database has been made (theres a another command to make the db
if name == 0 or description == 0 or ip == 0 or port == 0 or query_port == 0:
#some more checking
mycursor.execute("select * from source_server_info")
existingservers = len(mycursor.fetchall()) # finds the instance number it should use when inserting (primary key kind of)
mydb=msc(ctx.guild.id)
mycursor = mydb.cursor(buffered=False)
mycursor.execute(f"use `{str(ctx.guild.id)}`")
mycursor.execute(f"""INSERT INTO source_server_info (instance, name, description, ip, port, query_port) VALUES ({existingservers+1}, '{name}', '{description}', '{ip}', {port}, {query_port})""")
它应该只是将行插入到 mysql 中。它实际上做什么它绝对没有。没有给出错误,mysql上没有任何改变。我很可能是一个布偶,缺少一些愚蠢的东西,但我们将不胜感激。谢谢
【问题讨论】:
标签: python-3.x mysql-python discord.py-rewrite