gpt4 book ai didi

python - sqlite3.OperationalError : near ")": syntax error

转载 作者:行者123 更新时间:2023-12-03 21:28:27 28 4
gpt4 key购买 nike

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

如果有人可以提供帮助,我将不胜感激。

最佳答案

修复 sql_1 :

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

删除 ,之后 password text .

关于python - sqlite3.OperationalError : near ")": syntax error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42715315/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com