sqlite python插入
我以前也问过类似的问题,下面是我想要达到的目标的详细解释 我有两个sqlite表sqlite python插入,python,sqlite,Python,Sqlite,我以前也问过类似的问题,下面是我想要达到的目标的详细解释 我有两个sqlite表 表1是标准表,包含服务器、id、状态等字段 表2-包含服务器、id、状态、编号、日志文件等字段 表2为空,表1有值。我试图用表1中的条目填充表2。 我可以从表1中检索记录,但在尝试插入表2中时失败了。(但插入单个字段有效) 并且让我知道如何在insert失败时生成更有用的错误消息此语句已中断: self.cursor.execute("insert into server_table2(server,status,
表1是标准表,包含服务器、id、状态等字段 表2-包含服务器、id、状态、编号、日志文件等字段 表2为空,表1有值。我试图用表1中的条目填充表2。 我可以从表1中检索记录,但在尝试插入表2中时失败了。(但插入单个字段有效)
并且让我知道如何在insert失败时生成更有用的错误消息此语句已中断:
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
,因为我认为这可以节省大量时间。复制并粘贴生成的错误。是的..谢谢,我解决了它。我应该用这个(?,?)(记录[0],记录[1],记录[2]),而不是上面的…现在它工作了:)
self.cursor.execute("insert into server_table2(server,status,id) values (?,?,?)",record[0:2])