作者rs6000 (正義的胖虎)
看板Python
標題[問題] sqlite寫入問題
時間Fri Oct 27 13:55:26 2017
想請教一下板上的大大
在寫入資料庫時要如何帶入自動編號的id值
my_list=['A','B','C','D']
c.execute("INSERT INTO my_table VALUES(?)", (my_list))
my_list的元素就是對應到資料庫的欄位
但id值是用自動編號
我以為上面那條sql可以忽略id..但不行
那要怎麼把自動編號的id補到程式碼裡呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.41.46.177
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1509083728.A.051.html
1F:推 hl4: Create table 的時候就決定了吧 10/27 15:10
2F:→ uranusjr: 在建 table 的時候就必須要有一個 integer primary key 10/27 15:51
3F:→ uranusjr: autoincrement 了, 不是 insert 的時候加入 10/27 15:51
5F:→ rs6000: id是pk鍵&auto 但還是程式還是會出錯 10/27 18:27
7F:推 cutekid: 2樓 u 大有提供解法了: 10/27 19:11
8F:→ cutekid: insert into profile values(NULL,?,?,?) 10/27 19:12
9F:→ rs6000: 我已經設id是pk&auto ... 10/27 19:21
10F:推 cutekid: insert into profile values(NULL,?,?,?),記得加 NULL 10/27 19:28
11F:→ rs6000: 還我海殤君感謝樓上的大大 10/27 19:57
12F:→ rs6000: ....推文出錯...lol... 10/27 19:58
13F:→ rs6000: 感謝啦 :) 10/27 19:58