0

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?

asked Jan 16, 2016 at 13:19
0

1 Answer 1

0

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,))`
answered Jan 16, 2016 at 13:22
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I was mixing up this syntax in my head: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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.