写作:
post = cur.execute("""SELECT id FROM ochered""")
print(post)
我得到:
<sqlite3.Cursor object at 0x0000000003E0FB20>
所有代码:
import config
import json
from aiogram import Bot, Dispatcher, executor, types
import sqlite3 as sq
import asyncio
import aioschedule
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)
global base, cur
base = sq.connect('ochered.db')
cur = base.cursor()
async def on_startup(_):
scheduler()
async def scheduler():
aioschedule.every(1).minutes.do(public)
while True:
await aioschedule.run_pending()
await asyncio.sleep(1)
@dp.message_handler(content_types=['photo', 'video'])
async def dobavlenie(message: types.Message):
base.execute('CREATE TABLE IF NOT EXISTS ochered(id, type)')
if message.photo:
params = ( message.photo[0].file_id, 'photo')
elif message.video:
params = ( message.video.file_id, 'video')
cur.execute('INSERT INTO ochered VALUES (?, ?)', params)
base.commit()
#@dp.message_handler()
async def dobavlenie(message: types.Message):
chmo = cur.fetchone()
print(chmo)
@dp.message_handler()
async def public(message: types.Message):
post = cur.execute("""SELECT id FROM ochered""")
print(post)
#await bot.send_photo( chat_id = config.chat_id, photo = post[0])
#cur.execute('DELETE id FROM ochered WHERE ROW_NOMBER == 1')
executor.start_polling(dp, skip_updates=True)
因为在执行之后,如果命令应该返回一些东西,你需要通过 fetch 选择值。
https://docs.python.org/3/library/sqlite3.html