On Jul 20, 12:13 am, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Jul 19, 2008, at 9:10 AM, Contact 42 wrote:
>
>
>
>
>
> > Hi,
>
> > I am using sa 0.5b2 under python 2.5.
>
> > Should the following code commit myobj.
>
> > engine = create_engine(appconfig.dburi, strategy='threadlocal')
> > Session = scoped_session(sessionmaker(bind=engine, autoflush=True,
> > autocommit=True))
>
> > sess = Session()
> > engine.begin()
> > sess.add(myobj)
> > engine.commit()
>
> > I am noticing that it does not. However, if I do
>
> > sess = Session()
> > sess.begin()
> > sess.add(myobj)
> > sess.commit()
>
> > it works.
>
> > Am I missing something ?
>
> The "commit()" method on Session has the additional functionality of
> flushing itself when called. If you want to use Session within a
> threadlocal transaction at the engine level, you'd have to ensure that
> you flush() the session manually before commit.
I thought autoflush=True would do that for me. This is not a problem,
I'll just use the session transaction interface.
>
> These days the Session has become more prominent as the center of
> transactional control, however, so you might find it easier to just go
> through scoped_session() for transaction control entirely. Session
> has an execute() and connection() method for issuing raw SQL too.
Yeah this is great. I will move all my engine stuff to use the session
directly.
> If
> you continue to use the threadlocal engine strategy, then implicit
> executions (i.e. somestatement.execute()) should participate in the
> same transaction as the Session.
Is there a warning in that "If" ? Is the threadlocal strategy not the
most popular for web programs ?
Thanks,
Huy
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---