On 10/26/07, Philip Cooper <[EMAIL PROTECTED]> wrote:
>
> Shaimardanov Rushan at about 10/26/07 5:31 AM said:
> > How should I execute SA queries in Pylons controllers? (without using
> > mapping)
>
> you need Session from model
>
> > The using of sqlalchemy.sql.select (as whown in SA tutorial gives an error
> > "<class 'sqlalchemy.exceptions.InvalidRequestError'>:
> > This Compiled object is not bound to any Engine or Connection."
> >
> > My code is:
> >
> > from tcounter.model import stats_table #my table
> > from sqlalchemy.sql import select
> >
> > #in controller's method:
> > s = select([stats_table])
> You should have Session in your model.py check current pylons cookbook
> stuff
>
> from tcounter.model import Session
> res = Session.execute(s)
> > res = s.execute()
> >
> > data = res.fetchall()

A bit of background.  All SQL operations require an engine or
connection, which you can pass with every method (bind=engine), or
bind to the session or metadata.  SQLAlchemy 0.4 added Session.execute
so that you can use the session's engine with non-orm queries: this
avoids transaction issues if both orm and non-orm queries are used in
the same session.


-- 
Mike Orr <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to