On Mar 10, 2008, at 6:24 AM, exhuma.twn wrote:
>
> Hello sqlalchemy,
>
>
> I need to execute a select-statement on a table, which uses a custom
> stored procedure inside the "WHERE" clause. That's why I need to use a
> "text()" ClauseElement.
provded the stored procedure is called in regular function-with-
parenthesis, syntax, the "func" operator can generate any procedure
name without the need for text():
expr = bindparam('r', type=Float) >=
func.ldistance(func.Point(bindparam('x'), bindparam('y'))
the bind parameter values above would be specified to the execute()
method on an engine or connection, or if using the ORM the .params()
method on Query.
However, if all you're trying to do is query for some specific values
and have the underlying SQL use bind parameters, SQLAlchemy does that
for you in all cases. We could more easily write the above as:
expr = literal(5.0) >= func.ldistance(func.Point(3.0, 4.0))
printing the above gives us:
>>> print expr
:param_1 >= ldistance(Point(:Point_1, :Point_2))
Where the bind parameter values are revealed at compilation/execution
time (and you dont need to worry about them):
>>> print expr.compile().params
>
> I also know I could use the info_table object (the Table object
> assigned to "Info"), But then I would receive simple table rows as
> result-set. But the mapped "Info" object contains other useful methods
> I would need. So I would much rather execute a select statement on the
> mapped "Info" object.
So our above WHERE condition goes into the filter() of a Query:
sess.query(Info).filter(expr).all()
and thats all there is to it.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---