> -----Original Message-----
> From: sqlalchemy@googlegroups.com 
> [mailto:sqlalch...@googlegroups.com] On Behalf Of Manlio Perillo
> Sent: 29 January 2010 13:15
> To: sqlalchemy@googlegroups.com
> Subject: [sqlalchemy] problem when executing multiple insert 
> statements and boolean type
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi.
> 
> I'm here again with a problem I don't know if it is a bug in 
> SA or in my
> code.
> 
> Here is the offending code:
> 
> from sqlalchemy import schema, types, sql, create_engine
> 
> 
> metadata = schema.MetaData()
> test = schema.Table(
>     'test', metadata,
>     schema.Column('x', types.Integer, primary_key=True),
>     schema.Column('y', types.Boolean, default=True, nullable=False)
>     )
> 
> engine = create_engine('sqlite://')
> engine.create(metadata)
> 
> try:
>     params = [ {'x': 1}, {'x': 2, 'y': False} ]
>     engine.execute(test.insert(), params)
>     print engine.execute(test.select()).fetchall()
> finally:
>     engine.drop(metadata)
> 
> 
> This should print:
>   [(1, True), (2, False)]
> and instead it prints
>   [(1, True), (2, True)]
> 
> 
> 
> Thanks  Manlio

This is explained in the last paragraph of
http://www.sqlalchemy.org/docs/sqlexpression.html#executing-multiple-sta
tements:

"""
When executing multiple sets of parameters, each dictionary must have
the same set of keys; i.e. you cant have fewer keys in some dictionaries
than others. This is because the Insert statement is compiled against
the first dictionary in the list, and it's assumed that all subsequent
argument dictionaries are compatible with that statement.
"""

I think a check has been added in 0.6 so that an exception is raised if
you don't follow this advice.

Hope that helps,

Simon

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

Reply via email to