社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

无法在python sqlite中使用“ExecuteMay”更新表

Peter.k • 3 年前 • 1241 次点击  

我必须使用以下表达式更新简单表格:

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
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129447
 
1241 次点击  
文章 [ 2 ]  |  最新文章 3 年前
mkrieger1
Reply   •   1 楼
mkrieger1    3 年前

executemany 需要嵌套序列并解释 v[0] 作为要插入的第一个序列。

就好像你用过 execute(..., v[0]) .

它说“提供了10个参数”,因为 v[0] 正好是长度为10的字符串。

forpas
Reply   •   2 楼
forpas    3 年前

如果使用 execute() 也许这就是你想做的,但是 executemany() 应该使用元组中的一个元组作为第二个参数,因为这是 执行官 ,多次执行同一条语句,每次提供不同的参数列表:

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