2017-03-10 28 views
0
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, 
     );""" 

私はこのコードを実行しようとしていますが、私は次のエラーを取得する...sqlite3.OperationalError:近い「)」:構文エラー

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 

誰もが、私はそれを感謝することができます。

+0

パスワードテキストの後に削除します。 –

答えて

1

最後の "、"を "パスワードテキスト"の後に削除します。コンマは、別のフィールドが続くことを示します。

3

修正sql_1

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

password text,を削除します。

関連する問題