Trying to execute insert an item coming from a list:`
item=u'Sunil Goyal'
c.execute('''INSERT INTO bpersons(person_name) VALUES (?)''',item)`
is simple enough, but it returns
Incorrect number of bindings supplied. The current statement uses 1, and there are 11 supplied.
Clearly instead of reading item as one element, it is reading characters. There is no problem with the earlier code which returns this list:
>>> if meta[7]:#bcoz list could be empty also
for item in meta[7]:
print item
Sunil Goyal
Rehan Yar Khan
Khan
Kae Capital
Ashish Shankar
Karthik Reddy
Feroze Azeez
len(meta[7]) 7
Any idea where I am going wrong?
1 Answer 1
insert is looking for an iterable (documentation) and this succeeds because your unicode string is an iterable, but you should put it inside of a tuple or list to be handled properly by sqlite3.
c.execute('''INSERT INTO bpersons(person_name) VALUES (?)''',(item,))`
1 Comment
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 20000.00 );. Why this difference, tho? COMPANY.ADDRESS will read 'California' but (?,?,?,?,?) will not?