Python does not update the value of the database with PyMySQL

1

Code :

import discord
import asyncio
from PyMySQL import pymysql

# Código sin importancia
if message.content.startswith('!points'):
    clist = message.content.split(' ')
    if len(clist) > 1:
        # Código sin importancia
    else:
        cursor.execute("SELECT * FROM usuario where discord_id = "+str(message.author.id))
        bdb=cursor.fetchall()
        print (bdb)
        for usuario in bdb:
            puntos=usuario[3]
            await client.send_message(message.channel, content=('Tienes '+str(puntos)+' puntos!'))

I'm using the modules of discord.py , asyncio and PyMySQL in Python3.5. A different script adds points in the database every 10 seconds. There is more code, but basically what it does is detect new messages in discord that start with ! Points , and then check if you have only sent ! Points or if you have sent ! points [something] .

Problem :

The problem comes when they send only ! points (in else: ). Does the search cursor.execute("SELECT * FROM usuario where discord_id = "+str(message.author.id)) . And it ends up taking out the amount of points that the person has. The first search does perfectly, and sends the points that person has at that exact moment, but the next time you put ! Points , the value is always the same value that came out the first once .

I guess the error is in these lines

cursor.execute("SELECT * FROM usuario where discord_id = "+str(message.author.id))
bdb=cursor.fetchall()

How could I fix the error I said? Are there better ways to do the search?

    
asked by ImHarvol 30.08.2017 в 19:11
source

1 answer

0

I have found the solution. You have to add db.commit() to the end of else: , so it looks like this:

else:
    cursor.execute("SELECT * FROM usuario where discord_id = "+str(message.author.id))
    bdb=cursor.fetchall()
    print (bdb)
    for usuario in bdb:
        puntos=usuario[3]
        await client.send_message(message.channel, content=('Tienes '+str(puntos)+' puntos!'))
    db.commit()
    
answered by 30.08.2017 / 19:42
source