我的表中的列看起來像這樣:更新列表中的sqlite3 db
Name1 | Name2 |重量|高度| Number1 | Number2
一些Number1和Number2列是空的,我只是試圖只更新空行。要做到這一點,我有6個清單:
List1 contains the values in Name1, in the same order
List2 contains the values in Name2, in the same order
List3 contains the values in Name1, but in a different order
List4 contains the values in Name2, but in the same order as List3
列出5,6包含在數字1和數字2分別被插入的值,並且在相同的順序列出3和4
那麼什麼我試圖做的是:
在表1中搜索Number1和Number2中具有空值的所有行;
搜索列出3或4以匹配Name1或Name2的值,因此如果在列表3中找到匹配項,Number1和Number2的值仍應分別填入列表5和列表6中。
所以我想的代碼看起來是這樣的:
for i in Name1:
c.execute("SELECT * FROM Mytable WHERE Number1 IS NULL")
if Name1 is List3:
c.execute("INSERT INTO Mytable (Number1, Number2)" " VALUES (?, ?)",
(List5[i], List6[i]))
elif Name2 is List4:
c.execute("INSERT INTO Mytable (Number1, Number2)" " VALUES (?, ?)",
(List5[i], List6[i]))
然而,當我運行它,它增加了行的表,但沒有值數字1或數字2。我哪裏錯了?