O
O
Olkimn2022-01-21 10:27:48
Python
Olkimn, 2022-01-21 10:27:48

SQL how to fix error?

for guild in bot.guilds:
    for member in guild.members:
      if cursor.execute(f"SELECT id FROM users WHERE id = {member.id} AND server_id = {guild.id}").fetchone() is None:
        cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id},0,0,{guild.id})")
        

      else:
        pass
  connection.commit()


Throws an error: line 59, in on_ready
cursor.execute(f"INSERT INTO users VALUES ('{member}', '{member.id}',0,0,'{guild.id}')")
sqlite3.OperationalError : near "t": syntax error. How to solve the problem? This has not happened before

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-21
@Olkimn

1. Do not generate queries through string formatting. Use placeholders. Starting with "the DB-API's parameter substitution"
2. If you need to insert a record if it doesn't exist, or do nothing if it does, read about INSERT ON CONFLICT DO NOTHING. Well, or about INSERT ON CONFLICT DO UPDATE, if you need to "insert a new one or update an existing one."

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question