[Tutor] sqlite3 place holder problem
Alan Gauld
alan.gauld at btinternet.com
Fri Oct 4 11:48:15 CEST 2013
On 04/10/13 03:14, Alex Kleider wrote:
> Thanks, I discovered that when I went I read further in the documentation.
> This is the part that lead me a stray:
> """
> # Larger example that inserts many records at a time
> purchases = [('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
> ('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
> ('2006-04-06', 'SELL', 'IBM', 500, 53.00),
> ]
> c.executemany('INSERT INTO stocks VALUES (?,?,?,?,?)', purchases)
> """
> I made the incorrect assumption that individual question marks
> represented tuples, (as they do here with 'executemany') but I guess not
> so with 'execute'.
I'm not sure you got that right.
There are 5 question marks there, one for each value item to be inserted.
There are 5 values in each tuple in purchases.
Therefore the question marks do not represent the tuples, they represent
the values in the tuples. Just like in execute()
executemany() performs an execute() on each item in the purchases
list, passing the tuple content into the execute.
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list