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
-~----------~----~----~----~------~----~------~--~---