我以前问过类似的问题,这里是我想要实现的目标的详细解释
我有两个 sqlite 表
table1 - 是标准表 - 具有服务器、id、状态等字段
table2 - 具有服务器、id、状态、数字、日志文件等字段
Table2 为空,Table1 有值。我正在尝试用 table1 中的条目填充 table2 。
我可以从 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
因为我认为这可以节省你大量的时间。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)