2017-06-22 61 views
-3

我通過用戶輸入獲取一些數據,然後我必須在sqlite表中插入相同的數據。在sqlite表中插入Python腳本

conn = sqlite.connect('c:/sqlite/test.db') 
c = conn.cursor() 

c.execute("Select Max(person_id) from persons") 
person_id =c.fetchone()[0] 

person_name = input ("Please provide User Name: ") 
user_id= input("Please user_id table: ") 
home_floor = input ("Please provide home floor for user: ") 
start_dt= input("Please enter start date (yyyy-mm-dd) for User : ") 
end_dt = input ("Please enter end date (yyyy-mm-dd) for User: ") 

c.execute('insert into Person values (%s,%s,%s,%s,%s,%s) person_id,person_name,user_id,home_floor,start_dt,end_dt) 
+2

瞭解如何創建[MCVE] –

回答

-1

使用這個代替 -

c.execute("insert into Person values (?,?,?,?,?,?)", (person_id,person_name,user_id,home_floor,start_dt,end_dt)) 

此外,插入後別忘了commit()。你的情況應該是 -

conn.commit() 
+0

史迪威我得到'錯誤附近「%」:語法error' – newbie

+0

@newbie,但我提供的代碼,沒有' %'。更改你的最後一行與我的 – kuro

+0

謝謝它的工作,錯誤是爲了一些其他lne :-( – newbie