sqlite python insert
I hav开发者_如何学JAVAe asked similar question before , here is detailed explanation of what i'm trying to achieve
I have two sqlite tables
table1 - is standard table - has fields like server,id,status table2 - has fields like server,id,status,number,logfileTable2 is empty and Table1 has values. I'm trying to fill table2 with entries from table1. I can retrieve records from table1 ,but while trying to insert into table2 it fails.(but inserting a single field works)
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],));
And also let me know how to produce more useful error messages when insert fails
This statement is broken:
self.cursor.execute("insert into server_table2(server,status,id) values (?,?,?)",(record[0],)(record[1],),(record[2],));
it should read:
self.cursor.execute("insert into server_table2(server,status,id) values (?,?,?)",record[0:2])
And you might want to look into executemany
as I think it could save you a ton of time.
精彩评论