Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sqlite python插入_Python_Sqlite - Fatal编程技术网

sqlite python插入

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,

我以前也问过类似的问题,下面是我想要达到的目标的详细解释

我有两个sqlite表
表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])