On 07/27/2011 10:42 AM, werner wrote:
> I like to use a stored procure which needs a input parameter in
> something like this:
>
> seltest = db.sa.select(["id",
> "name"]).select_from(db.sa.func.someStoredProc(2)).alias()
> seltestm = db.sao.mapper(ATest, seltest, primary_key=[seltest.c.id])
> result = session.query(seltestm).get(73)
>
> above works, but I would really need to replace the hardcoded "2" with
> a function, i.e.:
>
> seltest = db.sa.select(["id",
> "name"]).select_from(db.sa.func.someStoredProc(getSomeUserValue())).alias()
> seltestm = db.sao.mapper(ATest, seltest, primary_key=[seltest.c.id])
>
> # set the SomeUserValue here and then do
> result = session.query(seltestm).get(73)
>
> tried using functools.partial but I get a InterfaceError exception.
>
> Werner
>
I believe you want to replace getSomeUserValue() with
sa.bindparam(callable_=getSomeUserValue). See the docs at
http://www.sqlalchemy.org/docs/core/expression_api.html#sqlalchemy.sql.expression.bindparam.

As an aside, do you really want to map a class against a dynamic query?
I'm not sure how well the ORM deals with that. At the very least, I
think you need to ensure that SomeUserValue does not change while using
the session.

-Conor

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to