Answer the question
In order to leave comments, you need to log in
How to bind in AIOGRAM on InlineKeyboardButton the button to delete a column from SQLITE?
Hello everyone, during the development of the administrator menu (via telegram chat), I thought about the fact that the administrator, although he can enter / add some data, it would be cool if he could delete them as well, and not climb every time SQLite and do everything manually. So, below is the code that I tried to implement this task
@dp.message_handler(text="Удалить из базы данных")
async def sql_del(message: types.Message):
if message.from_user.id == Admin_Id:
read = await sqlite_db.sql_read2()
for ret in read:
await bot.send_message(message.from_user.id, text=f'{ret[:]}', reply_markup=InlineKeyboardMarkup().
add(InlineKeyboardButton(f'Удалить {ret[:]}', callback_data=f'del {ret[:]}')))
@dp.callback_query_handler(lambda x: x.data and x.data.startswith('del '))
async def del_callback_run(call: types.CallbackQuery):
await sqlite_db.sql_delete(call.data.replace('del ', ''))
await call.answer(text=f'{call.data.replace("del ", "")} удалено.', show_alert=True)
async def sql_delete(data):
cur.execute('DELETE FROM menu WHERE variable == ? ', (data,))
base.commit()
'DELETE FROM menu WHERE variable=(?)'
DELETE FROM menu
WHERE variable= 'data';
Answer the question
In order to leave comments, you need to log in
In my opinion it should be something like this:
async def sql_delete(data):
cur.execute('DELETE FROM menu WHERE variable = ?;', (data,))
base.commit()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question