ive been alerted that the bindparam() function doesnt work inside of
in_() and theres a new ticket that addresses this issue, but i havent
had time to confirm.
however, even if this is fixed, your usage would still be incorrect
(except perhaps with postgres, which supports an ARRAY type
implicitly); normally you cant pass an array to a bind parameter
value. you would have to have a bindparam() instance for each scalar
value youd like to pass, i.e.:
s = table.select(table.c.somecol.in_(bindparam('param1'),
bindparam('param2'), bindparam('param3')))
s.execute(param1=2, param2=3, param3=4)
On Feb 10, 4:46 pm, "dykang" <[EMAIL PROTECTED]> wrote:
> from sqlalchemy import *
> I was having some trouble understanding how to use the bindparams, and
> I haven't been able to get them to work with the in_ operator. The
> following code is a simple demonstration of what I'm trying (with
> mysql). It connects to a db, creates a small table and then tries to
> compile and execute a query that uses in_. When I try to execute the
> code, I get the following exception:
> sqlalchemy.exceptions.SQLError: (TypeError) not all arguments
> converted during string formatting 'SELECT testings.id,
> testings.some_data, testings.some_int \nFROM testings \nWHERE
> testings.id = %s' [[2, 3, 4]]
>
> I'm not really clear on how to use the bindparams properly, but this
> seems to be incorrect, any help would be appreciated,
>
> David
> #==============begin source below
>
> meta = DynamicMetaData ()
> meta.connect ('some uri')
> meta.engine.echo=True
> dbsession = create_session (bind_to=(meta.engine))
>
> TestTbl = Table ('testings', meta,
> Column ('id', Integer, Sequence ('testings_id_seq'),
> primary_key=True),
> Column ('some_data', Unicode (40)),
> Column ('some_int', Integer),
> mysql_engine='InnoDB')
>
> class Testing (object):
> pass
>
> TestTbl.create ()
>
> s = select ([TestTbl], TestTbl.c.id.in_(bindparam('my_id'))).compile
> ()
> some_mapper = mapper (Testing, TestTbl)
> results = dbsession.query(Testing).instances (s.execute(my_id=[2,3,4]))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---