I'm trying do delete a user from my database using python and sqlite.
import sqlite3
database_connection = sqlite3.connect('test.db')
delete_username_input = input("Which user you would like to delete?\n\n")
sql = ("DELETE * from USERS where USERNAME = ?")
args = (delete_username_input)
database_connection.execute(sql, args)
database_connection.commit()
database_connection.close()
When running the code above, I get the following error:
sqlite3.OperationalError: near "*": syntax error
Any idea what might be causing this error?
The table that I use has been created using the following syntax:
conn.execute('''CREATE TABLE USERS
(ID INTEGER PRIMARY KEY AUTOINCREMENT,
USERNAME TEXT NOT NULL,
PASSWORD TEXT NOT NULL,
WINS FLOAT NOT NULL,
LOSES FLOAT NOT NULL,
GAMESPLAYED FLOAT NOT NULL,
WINPERCENT FLOAT NOT NULL );''')
Any help will be appreciated.
asked Aug 2, 2017 at 8:16
B.Turris
851 gold badge1 silver badge5 bronze badges
1 Answer 1
Your SQL syntax is wrong. It should be
DELETE from USERS where USERNAME = ?
without the *
Check it out here
answered Aug 2, 2017 at 8:17
moritzg
4,4145 gold badges41 silver badges63 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
B.Turris
Yes that's it, thank you. Also the database_connection.execute(sql, args) should've been database_connection.execute(sql, (args,)).
default