Answer the question
In order to leave comments, you need to log in
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
#! /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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question