A
A
AlexaAioGram2021-07-24 15:31:30
Python
AlexaAioGram, 2021-07-24 15:31:30

How to update data in sqlite?

I decided to make a casino for fun ( 'naturally not real' )
In general, there was such a problem, when he wins or loses, the balance should be updated,
but instead it gives the following error:

c.execute('UPDATE user_message SET (?)', (balance,))
sqlite3.OperationalError: near "?": syntax error


Here is the code:
Database:

def update_balance(balance: int):
    conn = get_connection()
    c = conn.cursor()
    c.execute('UPDATE user_message SET (?)', (balance,))
    return c.fetchone()


Here is the game:

@dp.callback_query_handler(text='red')
    async def ssda(call: CallbackQuery):
        await call.answer()
        result = random.choice(random_rulet)
        if result == 'Красное':
            await call.message.answer(f'Выпало {result}, Вы победили!')
            update_balance(balance=+ ctavka)
        else:
            update_balance(balance=+ ctavka)
            await call.message.answer(f'Выпало {result}, Вы проиграли!')


I hope someone can help)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexaAioGram, 2021-07-24
@AlexaAioGram

I decided in the end myself:
It was right to write like this

def update_balance(balance: int):
    conn = get_connection()
    c = conn.cursor()
    c.execute('UPDATE user_message SET balance=(?)', (balance,))
    return c.fetchone()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question