簡體   English   中英

無法使用 python 中的“executemany”更新表 sqlite

[英]Can't update table using "executemany" in python sqlite

我必須使用以下表達式更新簡單表:

cur.executemany('UPDATE earths SET population=?, density=?, tilt=?, "land area"=?, dobe=?, livity=? WHERE sid=' + str(dc['sid']) + ' AND nr=' + str(dc['nr']), v)

打印它得到的內容:

('UPDATE earths SET population=?, density=?, tilt=?, "land area"=?, dobe=?, livity=? WHERE sid=15821 AND nr=8',
 ['1360425627', '2.79', '17.33', '486857065.504', '17.88371', '0.08'])

我得到的錯誤是:

ProgrammingError: Incorrect number of bindings supplied. The current statement uses 6, and there are 10 supplied.

我不知道程序如何從 6 元素列表中看到 10 個值。 有任何想法嗎? 該表沒問題 - 一個接一個地插入數據可以得出正確的值。 它看起來

UPDATE earths SET population=1360425627, density=2.79, tilt=17.33, "land area"=486857065.504, dobe=17.88371, livity=0.08 WHERE sid=15821 AND nr=8

如果你使用execute()你的代碼會工作,也許這就是你想要做的,但是對於executemany()你應該使用元組的元組作為第二個參數,因為這是executemany()的要點,執行多次使用相同的語句,每次都提供不同的參數列表:

v = [('1360425627', '2.79', '17.33', '486857065.504', '17.88371', '0.08'),]
cur.executemany('UPDATE ...', v)

executemany期望嵌套序列並將v[0]解釋為要插入的第一個序列。

就好像您使用過execute(..., v[0])一樣。

它說“10 arguments supplied”因為v[0]恰好是一個長度為 10 的字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM