简体   繁体   中英

Python sqlite3 Operational Error

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.

Your SQL syntax is wrong. It should be

DELETE from USERS where USERNAME = ?

without the *

Check it out here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM