On Sep 23, 2008, at 11:03 AM, Andrew wrote:
>
>
> Hi:
>
> I have been having problems in attempting to rebind a given Session
> object/class to a different engine instance. It seems that it can only
> be bound once. Subsequent sql statements post to the original binding.
> I am using sqlalchemy 0.4.6 with elixir. Here is an example:
>
>
> __session__ = scoped_session(sessionmaker(...))
>
> Session.configure(bind=engine1)
>
> # do sql ops here on engine1 via elixir
>
> __session__.configure(bind=engine2)
this is the wrong approach. configure() binds the overall
scoped_session, which is not itself a session but rather a container
of many sessions as well as a factory for new sessions, to a new
engine which only takes effect upon the next creation of a Session.
configure() is only used for an application which would like to
establish a scoped_session but does not yet have an available engine.
To bind a single session to an engine, simply assign the "bind"
attribute:
mysession.bind = someengine
when using a scoped_session(), the current session is available by
calling it:
mysession = __session__()
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---