0
votes

Hello I new in the sqlite world and here is my problem. Trying to fix a twitter bot an error occured. Here is the code to modify and the error. Tell me if you need the entire code or other informations

def CreateTables(user):
   connexion = sqlite3.connect('data.db')
   c = connexion.cursor()
   c.execute('''CREATE TABLE IF NOT EXISTS {tab}
   (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, compte text, date DATE);'''.format(tab=user.screen_name))
   c.close()
   connexion.commit()
Traceback (most recent call last):
  File "C:\Users\User\Documents\Terminale\Python\Twitter bot\BotTwitter-master\main.py", line 53, in <module>
    GestionFollow.CreateTables(user)
  File "C:\Users\User\Documents\Terminale\Python\Twitter bot\BotTwitter-master\GestionFollow.py", line 12, in CreateTables
    (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, compte text, date DATE);'''.format(tab=user.screen_name))
sqlite3.OperationalError: unrecognized token: "361Yra"

1
unrelated, but do you really want to create a table for every user? that's not very scalable. - DeepSpace
Please provide a minimal reproducible example which others can run on their computer. - IonicSolutions
Could you show the class code for the parameter user? - unkn0wn.dev
This isn't my code I'm just modifying it it already have been coded like this and it seems to work - Hugo361

1 Answers

0
votes

You are trying to create a table with a name that starts with a digit: 361Yra and this is not allowed.
What you can do is enclose the name in square brackets: [361Yra]
Although I'm not an expert in Python, use something like this:

.format(tab="[" + user.screen_name + "]")