2

I have 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,logfile

Table2 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

2
  • Copy and paste the error that is generated. Commented Jan 25, 2010 at 6:42
  • Yes..thanks I solved it . I should have used this (?,?,?"),(record[0],record[1],record[2],) instead of above ... Now it's working :) Commented Jan 25, 2010 at 6:48

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.