Hello all,
I'm having trouble using SQLAlchemy 0.50.rc3 and "like" query filters with the
psycopg2 adapter:
class Activity(Base):
__tablename__ = 'activities'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(Unicode(100), index=True)
[...]
filter_name = 'john';
activities = db_session.query(model.Activity)
activities = activities.filter(model.Activity.name.like('%%' + filter_name +
'%%'))
The query run from the above statements does not get expanded by the adapter:
SELECT activities.id AS activities_id, activities.name AS activities_name
FROM activities
WHERE activities.name LIKE %(name_1)s
This syntax:
activities = activities.filter("name ~~ '%%%s%%'" % filter_name) )
... will produce a valid SQL:
SELECT activities.id AS activities_id, activities.name AS activities_name
FROM activities
WHERE name ~~ '%john%'
However, it raises this error:
[...]
self.dialect.do_execute(cursor, statement, parameters, context=context)
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-
py2.5.egg/sqlalchemy/engine/default.py", line 122, in do_execute
cursor.execute(statement, parameters)
TypeError: 'dict' object is unindexable
I'm stuck. What should I be doing ? Use another syntax ? Replace psycopg2's
paramstyle to non-escaping mode ?
My environment:
Python 2.5.2
SQLAlchemy 0.5.0.rc3
PostgreSQL 8.30
psycopg 2.0.7
Ubuntu 8.04
--
Best Regards,
Steve Howe
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---