S
S
Sergo Zar2021-03-04 00:33:38
Python
Sergo Zar, 2021-03-04 00:33:38

sqlite3.OperationalError: near "all": syntax error?

I am making a program to send one message to all the people with whom I communicate in the telegram. And I wanted to create a database with data about them, but I get the following error:

Traceback (most recent call last):
  File "userbot1.py", line 32, in <module>
    cur.executemany('INSERT INTO all(tg_id,username,first_name,last_name) VALUES(?,?,?,?);', dialog)
sqlite3.OperationalError: near "all": syntax error

What did I do wrong?

(program code)
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from pyrogram import Client, filters
from pyrogram.errors import FloodWait

import sqlite3

app = Client("my_account")

con = sqlite3.connect('users.db')
cur = con.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS `all` (
        `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
        `tg_id` text(20) NOT NULL,
        `username` text(255) NOT NULL,
        `first_name` text(255) NOT NULL,
        `last_name` text(255) DEFAULT NULL)
    ''')
con.commit()

with app:
    

    for dialogs in app.iter_dialogs():
        if dialogs.chat.type == "private":
            tg_id = str(dialogs.chat.id)
            username = dialogs.chat.username
            first_name = dialogs.chat.first_name
            last_name = dialogs.chat.last_name
            dialog = (tg_id,username,first_name,last_name)
            cur.executemany('INSERT INTO all(tg_id,username,first_name,last_name) VALUES(?,?,?,?);', dialog)
            con.commit()

            cur.execute("SELECT * FROM all")
            all_results = cur.fetchall()
            print(all_results)
            
print(1)

app.run()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-03-04
@Sergomen

ALL is a reserved word in sqlite, to use it, it must be in `backticks`, or even better, rename the table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question