Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

Python MySQL connector UPDATE statement not updating all values

def mysql_update_discord_rank_data(author, rank_data):
    mydb, mycursor = connect_to_mysql()

    print(rank_data)

    mycursor.execute(f'UPDATE discord_levels SET `xp`={rank_data["xp"]}
        , `level`={rank_data["level"]}, `message_count`={rank_data["message_count"]}
            WHERE `discord_id`="{author.id}";')
    mydb.commit()

    mycursor.close()
    mydb.close()

This is the code that is giving me issues. I am attempting to modify xp, level, and message_count in the database table discord_levels.

The MySQL connection is good, I am running other queries just fine, it's just this one giving me issues. The MySQL query is also good, I have tried it in the MySQL console hoping that was the reason, unfortunately it wasn't.

The thing is, the xp and level columns are being updated accordingly, although the message_count column does not want to update at all. I have tried running the following MySQL query alone as well, to no avail (with a database commit afterwards).

mycursor.execute(f'UPDATE discord_levels SET `message_count`={int(rank_data["message_count"])} WHERE `discord_id`="{author.id}";')

I have checked if the value is actually being updated before the query is run, so I know that is also not the issue.

Does anyone have any idea on a fix for this or any idea as to what I am doing wrong?

question from:https://stackoverflow.com/questions/65852377/python-mysql-connector-update-statement-not-updating-all-values

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...