0

I think I'm updating my database wrong? It's not giving me a error, so it's probably something that I forgot to do or didn't notice. Anyways, I'm super stumped and the tutorial I was watching didn't have this problem.

Thanks for all the help in advance!

@bot.command(aliases = ['gen' , 'newacc'])
async def open_account(tendant):

    db = sqlite3.connect('leveling.sqlite')
    cursor = db.cursor()

    sqlupdate = (f'INSERT INTO leveling(user_id,xp, local_xp) VALUES(?,?,?)')

    val = (tendant.author.id, 0, 0)

    result = cursor.fetchall()
    await tendant.channel.send(result)
    cursor.execute(sqlupdate, val)
    db.close()

bot.run(token)
1
  • 1
    I think, you did not commit the changes. Try: db.commit() Add this above the db.close() Commented May 5, 2021 at 3:52

1 Answer 1

4

You need to commit your changes:

async def open_account(tendant):
    db = sqlite3.connect('leveling.sqlite')
    cursor = db.cursor()

    val = (tendant.author.id, 0, 0)
    cursor.execute('INSERT INTO leveling (user_id, xp, local_xp) VALUES(?, ?, ?)', val)
    
    # Save (commit) the changes
    db.commit()
    
    # We can close the connection if we are done with it.
    # Just be sure any changes have been committed or they will be lost.
    db.close()

See: https://docs.python.org/3/library/sqlite3.html

Sign up to request clarification or add additional context in comments.

1 Comment

Hey man, thanks! I tried to find docs on this but for some reason I haven't been able to find them. So thank you for the answer and thanks for the link to the docs!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.