gpt4 book ai didi

python - sqlite python 插入

转载 作者:太空宇宙 更新时间:2023-11-04 01:43:44 25 4
gpt4 key购买 nike

我之前问过类似的问题,这里是我想要实现的目标的详细解释

我有两个sqlite表
table1 - 是标准表 - 具有服务器、id、状态等字段table2 - 具有服务器、id、状态、编号、日志文件等字段

Table2 为空,Table1 有值。我试图用表 1 中的条目填充表 2。我可以从 table1 检索记录,但在尝试插入 table2 时失败。(但插入单个字段有效)

self.cursor.execute("select * from server_table1 limit (?)",t)
#insert into server_process

for record in self.server_pool_list:
print "--->",record # geting output like ---> (u'cloud_sys1', u'free', u'192.168.1.111')
self.cursor.execute("insert into server_table2(server,status,id) values (?,?,?)",(record[0],)(record[1],),(record[2],));

并且还让我知道如何在插入失败时生成更有用的错误消息

最佳答案

这条语句被打破了:

self.cursor.execute("insert into server_table2(server,status,id) values (?,?,?)",(record[0],)(record[1],),(record[2],));

它应该是:

self.cursor.execute("insert into server_table2(server,status,id) values (?,?,?)",record[0:2])

您可能想查看 executemany,因为我认为它可以为您节省大量时间。

关于python - sqlite python 插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2130641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com