Ok. I'll do some testing against other engines when I get a chance. Thanks for helping.
Cheers Chris Miles On Feb 6, 2:36 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: > sqlite doesn't include CREATE TABLE statements within the scope of a > transaction. I think that's a relatively rare behavior only seen in > Postgres, in fact - I dont think Oracle or MySQL have that behavior, > for example. > > On Feb 5, 2009, at 10:01 PM, Chris Miles wrote: > > > > > That did the trick, thanks. > > > Well, actually, it did the trick for PostgreSQL but sqlite isn't > > rolling back. The SA logs show the same commands are being sent to > > both. Here's an example: > > > $ rm test1.sqlite > > $ python sa_create_table_transaction_test.py > > 2009-02-06 13:39:29,006 INFO sqlalchemy.engine.base.Engine.0x..d0 > > BEGIN > > 2009-02-06 13:39:29,007 INFO sqlalchemy.engine.base.Engine.0x..d0 > > CREATE TABLE table1 ( > > col1 INTEGER > > ) > > > 2009-02-06 13:39:29,007 INFO sqlalchemy.engine.base.Engine.0x..d0 {} > > 2009-02-06 13:39:29,021 INFO sqlalchemy.engine.base.Engine.0x..d0 > > CREATE TABLE table2 ( > > col1 INTEGER > > ) > > > 2009-02-06 13:39:29,021 INFO sqlalchemy.engine.base.Engine.0x..d0 {} > > 2009-02-06 13:39:29,024 INFO sqlalchemy.engine.base.Engine.0x..d0 > > CREATE TABLE table2 ( > > col1 INTEGER > > ) > > > 2009-02-06 13:39:29,024 INFO sqlalchemy.engine.base.Engine.0x..d0 {} > > 2009-02-06 13:39:29,027 INFO sqlalchemy.engine.base.Engine.0x..d0 > > ROLLBACK > > $ sqlite3 test1.sqlite > > Loading resources from /Users/chris/.sqliterc > > SQLite version 3.4.0 > > Enter ".help" for instructions > > sqlite> .tables > > table1 table2 > > sqlite> > > > And the updated test script: > > > # ---- > > import sqlalchemy as sa > > > engine = sa.create_engine('sqlite:///test1.sqlite') > > #engine = sa.create_engine('postgres://localhost/test1') > > engine.echo = True > > metadata = sa.MetaData() > > > table1 = sa.Table("table1", metadata, > > sa.Column('col1', sa.types.Integer,), > > ) > > table2 = sa.Table("table2", metadata, > > sa.Column('col1', sa.types.Integer,), > > ) > > table3 = sa.Table("table3", metadata, > > sa.Column('col1', sa.types.Integer,), > > ) > > > metadata.bind = engine > > connection = engine.connect() > > trans = connection.begin() > > try: > > table1.create(bind=connection) > > table2.create(bind=connection) > > table2.create(bind=connection) > > table3.create(bind=connection) > > trans.commit() > > except: > > trans.rollback() > > # ---- > > > Cheers, > > Chris > > > On Feb 6, 2:08 am, Michael Bayer <mike...@zzzcomputing.com> wrote: > >> create() and create_all() take a "bind" argument which can be an > >> engine or connection. you want the connection in this case. > > >> On Feb 5, 2009, at 5:27 AM, Chris Miles wrote: > >>> I can't find away to link table.create() with the existing > >>> transaction. --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---