TypeError: Cursor.fetchall() takes no arguments (1 given)

Рейтинг: 0Ответов: 1Опубликовано: 21.01.2023

Вот код:

import sqlite3

class DataBase():
    def __init__(self, database_file):
        self.connect = sqlite3.connect(database_file, check_same_thread=False)
        self.cursor = self.connect.cursor()

    def add_queue(self, chat_id):
        with self.connect:
            return self.cursor.execute('INSERT INTO "queue" (chat_id) VALUES(?)', (chat_id,))

    def delete_queue(self, chat_id):
        with self.connect:
            return self.cursor.execute('DELETE FROM "queue" WHERE "chat_id" = ?', (chat_id,))


    def get_chat(self):
        with self.connect:
            chat = self.cursor.execute("SELECT * FROM 'queue'", ()).fetchall(1)
            if (bool(len(chat))):
                for row in chat:
                    return row[1]
            else: 
                return False
    
    def create_chat(self, chat_one, chat_two):
        with self.connect:
            if chat_two != 0:
                self.cursor.execute("DELETE FROM 'queue' WHERE 'chat_id' = ?", (chat_two,))
                self.cursor.execute("INSERT INTO 'chats' ('chat_one', 'chat_two') VALUE(?,?)", (chat_one, chat_two))
                return True
            else:
                return False

Это база данных моего телеграм бота и когда я его запускаю после команды пишет TypeError: Cursor.fetchall() takes no arguments (1 given)

Ответы

▲ 1

Ошибка в этом месте - .fetchall(1) (DataBase.get_chat). Чтобы получить один элемент можно воспользоваться fetchone() или fetchmany(1), функция же fetchall() не принимает аргументов и возвращает все значения.