sqlite3.OperationalError: 靠近")":语法错误

4
def staff_database(db_name,table_name,sql_1,admin):
    with sqlite3.connect('BehaviourManagement.db') as db:#connects this funtion to the database file
        cursor = db.cursor()#used to naviage around the database
        cursor.execute("select name from sqlite_master where name=?",(table_name,))#checks database for this table
        result = cursor.fetchall()#gets the results
        if len(result) != 1:#runs if statement if table present in the database
            cursor.execute(sql_1)#runs the sql statement
            db.commit()#ensures changes made to the database are saved
            cursor.execute(insert_to_login ,admin)
            db.commit()

sql_1 = """CREATE TABLE Login(
        ID INTEGER PRIMARY KEY autoincrement,
        username text, 
        password text,
        );"""

我正在尝试运行这段代码,但是出现了以下错误...

Traceback (most recent call last):
  File "M:\computer science a2\comp 3\login.py", line 151, in <module>
    staff_database(db_name, table_name,sql_1,admin)#runs the function
  File "M:\computer science a2\comp 3\login.py", line 62, in staff_database
    cursor.execute(sql_1)#runs the sql statement
sqlite3.OperationalError: near ")": syntax error

如果有人能帮忙,我会非常感激。


在密码文本后面删除逗号。 - János Farkas
2个回答

8

修复 sql_1

sql_1 = """CREATE TABLE Login(
        ID INTEGER PRIMARY KEY autoincrement,
        username text, 
        password text
        );"""

密码文本 后面移除 ,


3

在“密码文本”后面删除最后一个“,”。逗号表示另一个字段将跟随其后。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接