On Jul 19, 2007, at 2:00 PM, one.person wrote:

>
> Sorry for the noob question.  Why do I only end up with 2 inserted
> rows when doing this?
>
>>>> from sqlalchemy import *
>>>> db = create_engine('mysql://login:[EMAIL PROTECTED]/database')
>>>> metadata = BoundMetaData(db)
>>>> temptable = Table('temptable', metadata,
> ... Column('col1', Integer),
> ... Column('col2', String(10)))
>>>> temptable.create()
>>>> data = [(1, 'blah1'), (2, 'blah2'), (2, 'blah2'), (3, 'blah3'),  
>>>> (3, 'blah3'), (3, 'blah3')]
>>>> temptable.insert(values=data).execute()
> <sqlalchemy.engine.base.ResultProxy object at 0x01169C70>
>>>> s = temptable.select()
>>>> e = s.execute()
>>>> e.fetchall()
> [(1L, 'blah1'), (2L, 'blah2')]
>

the multiple values get passed to execute(), and with constructed SQL  
are always passed as dictionaries:

temptable.insert().execute({'col1':1, 'col2': 'blah1'}, {'col1':2,  
'col2': 'blah1'}, ....)

the way you were doing it, using "values", which expects a list of  
items in the same order as the columns, was binding (1, 'blah1') to  
col1 and (2, 'blah2') to col2.  but then later on in the chain, when  
converted to sqlite positional arguments, came out as [(1, 'blah1'),  
(2, 'blah2')], which then got picked up as a "list of tuples" , which  
is the clue that it should use executemany().


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to