2017-08-02 98 views
0

我想要刪除用戶從我的數據庫使用python和sqlite。Python的sqlite3操作錯誤

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() 

當運行上面的代碼,我得到以下錯誤:

sqlite3.OperationalError: near "*": syntax error 

任何想法可能會導致這個錯誤?

,我用已經使用以下語法創建表:

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 );''') 

任何幫助將不勝感激。

回答

1

您的SQL語法錯誤。它應該是

DELETE from USERS where USERNAME = ? 

沒有*

檢查出來here

+1

是,就是這樣,謝謝。另外,database_connection.execute(sql,args)應該是database_connection.execute(sql,(args,))。 –