Answer the question
In order to leave comments, you need to log in
Problem with inserting arguments in python sql query, what is the reason?
The request is not sent. The code:
def register_command(command: str, user_id: int):
time_now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
with sq.connect('history.db') as con:
cur = con.cursor()
cur.execute("""
INSERT INTO commands (user_id, date, command_name) VALUES (7 , {} , 'd')""".format(time_now))
line 38, in register_command
cur.execute("""
sqlite3.OperationalError: near "23": syntax error
"
Answer the question
In order to leave comments, you need to log in
Do not under any circumstances do this
cur.execute("""INSERT INTO commands (user_id, date, command_name) VALUES (7 , {} , 'd')""".format(time_now))
cur.execute("INSERT INTO commands (user_id, date, command_name) VALUES (7 , ?, 'd')", (time_now,))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question