A
A
Anton2021-08-03 11:18:06
SQLite
Anton, 2021-08-03 11:18:06

sqlite3 syntax error?

def add_server(self, server_id, server_name, ignore_id = 0, population_id = 0):
        if self.is_server_exist(server_id): print('Server is already in table'); return
        self.cur.execute('INSERT OR REPLACE INTO servers (server_id,  server_name, channel_id_for_monitoring_population, role_id_for_ignoring_score) VALUES ({}, {}, {}, {})'.format(server_id, server_name, ignore_id, population_id))
        self.conn.commit()
        print(f'Server {server_name} was added')


ERROR: sqlite3.OperationalError: near "server": syntax error

Same entry with another database, but everything works. Tell me please.
Below is the code for creating a table with fields.

self.cur.execute("""CREATE TABLE IF NOT EXISTS servers (
                    server_id INT PRIMARY KEY,
                    server_name TEXT,
                    channel_id_for_monitoring_population INT,
                    role_id_for_ignoring_score INT);
                    """)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-08-03
@sergey-gornostaev

Every week I write that you should not form queries by concatenation, interpolation and string formatting. Use prepared statements and you will be happy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question