【问题标题】:sqlite3.OperationalError: near ")": syntax errorsqlite3.OperationalError:靠近“)”:语法错误
【发布时间】:2017-03-10 09:53:17
【问题描述】:
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

如果有人能帮忙,我将不胜感激。

【问题讨论】:

  • 删除,密码文本后...

标签: python sqlite


【解决方案1】:

修复sql_1:

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

password text 之后删除,

【讨论】:

    【解决方案2】:

    删除“密码文本”之后的最后一个“,”。逗号表示后面有另一个字段。

    【讨论】:

      猜你喜欢
      • 2021-05-11
      • 2019-02-07
      • 2020-02-06
      • 2019-01-12
      • 2014-05-17
      • 2021-10-19
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多