On Feb 17, 2011, at 9:48 PM, Daniel Holth wrote: > Can someone help me understand why DDL seems to not be transactional here: > > import sqlalchemy > e = sqlalchemy.create_engine('sqlite://') > c = e.connect() > t = c.begin() > c.execute("CREATE TABLE foo (bar INTEGER)") > t.rollback() > > assert u'foo' in e.table_names() # True > > But, if I start up `sqlite3 db.db` and type: BEGIN; CREATE TABLE foo (bar > INTEGER); ROLLBACK; > > then no `foo` table is created. I am using SQLite 3.7.2. > > I am trying to write migration scripts that create a table and populate it, > or fail and rollback the entire transaction.
that's a product of Pysqlite. DDL isn't transactional with Pysqlite's default transaction settings. >>> import sqlite3 >>> c = sqlite3.connect(':memory:') >>> curs = c.cursor() >>> curs.execute("create table foo (id integer)") <sqlite3.Cursor object at 0x2f0160> >>> c.rollback() >>> curs = c.cursor() >>> curs.execute("select * from foo") <sqlite3.Cursor object at 0x2f02a0> >>> print curs.fetchall() [] > > Thanks. > > -- > 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. -- 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.