[Tutor] sqlite3 place holder problem

Alex Kleider akleider at sonic.net
Fri Oct 4 20:42:44 CEST 2013


On 2013-10-04 02:48, Alan Gauld wrote:
> 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

Ah, Ha!
Thanks for the clarification.
Now it is much more consistent (as I should have known that it would 
be.)



More information about the Tutor mailing list