14 May 22:12
Re: Savepoints not generated with MySQL?
From: Michael Bayer <mike_mp <at> zzzcomputing.com>
Subject: Re: Savepoints not generated with MySQL?
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-14 20:12:04 GMT
Subject: Re: Savepoints not generated with MySQL?
Newsgroups: gmane.comp.python.sqlalchemy.user
Date: 2008-05-14 20:12:04 GMT
two problems:
1. the "threadlocal" mode, not a widely used option, currently does
not support begin_nested() (which is somewhat of a surprise to me)
2. the inner() method issues no SQL. add a "sess.flush()" in there,
and do away with "threadlocal" to see it work.
On May 14, 2008, at 3:45 PM, Jacob Gabrielson wrote:
> from sqlalchemy import *
> from sqlalchemy.orm import *
>
> engine = create_engine('mysql://root <at> localhost/test', echo=True,
> strategy='threadlocal')
> meta = MetaData()
> meta.bind = engine
>
> test_table = Table('test_table', meta,
> Column('test_id', Integer, primary_key=True),
> Column('name', String(40)),
> mysql_engine='InnoDB')
>
> meta.create_all()
>
> class MyTest(object):
> def __init__(self, test_name):
> self.name = test_name
>
>
> mapper(MyTest, test_table)
>
> Session = sessionmaker(transactional=False, autoflush=True,
> bind=engine)
>
> def doit():
> sess = Session(transactional=False)
> sess.begin()
>
> t = MyTest("outer")
> sess.save(t)
> sess.flush()
>
> def inner():
> sess.begin_nested()
> t2 = MyTest("inner")
> sess.save(t2)
> sess.rollback()
>
> inner()
>
> sess.commit()
>
> if __name__ == '__main__':
> doit()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalchemy <at> googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
RSS Feed