On Tue, Oct 27, 2009 at 16:22 -0400, Michael Bayer wrote:
> Wolodja Wentland wrote:
> >
> > def create(self):
> > """Create this database"""
> > # set isolation level to AUTOCOMMIT
> > # postgres can't CREATE databases within a transaction
> > self._admin_engine.connect().connection.connection.set_isolation_level(
> > ISOLATION_LEVEL_AUTOCOMMIT)
> >
> > self.admin_session.execute('CREATE DATABASE %s'%(self.name))
> there's nothing about the above code that guarantees the connection on
> which you called set_isolation_level() is the one used by your
> session.execute(). I think you mean to call execute("CREATE DATABASE")
> on the connection returned by self._admin_engine.connect().
You are right! I changed the code to this:
--- snip ---
def create(self):
"""Create this database"""
# set isolation level to AUTOCOMMIT
# postgres can't CREATE databases within a transaction
conn = self._admin_engine.connect()
conn.connection.connection.set_isolation_level(
ISOLATION_LEVEL_AUTOCOMMIT)
conn.execute('CREATE DATABASE %s'%(self.name))
conn.connection.connection.set_isolation_level(
ISOLATION_LEVEL_READ_COMMITTED)
--- snip ---
and it works like a charm.
But i still have some little questions...
* Is there an even better way to do this? ;-)
* Is it necessary to set the isolation level to the value it had
before I set it to ISOLATION_LEVEL_AUTOCOMMIT to make sure that no
connection uses ISOLATION_LEVEL_AUTOCOMMIT in the future without
explicitly setting that?
(I will change the code so it remembers the value of isolation_level
and use that instead of it to ISOLATION_LEVEL_READ_COMMITTED
explicitly)
* Why the .connection.connection ? I remember that I had to write just
one .connection in the past.
And one more word... This is the fastest mailing list I have ever used.
Thank you so much for reacting so fast on this ML, thank you very much
for SA and thanks for the solution to my problem!
have a great afternoon
Wolodja Wentland
signature.asc
Description: Digital signature
