On Jan 26, 2011, at 5:16 PM, A.M. wrote: > Hello, > > While working on a database test with nose, I dug into sqlalchemy 0.6.6 until > I found these lines: > > class DDLElement(expression.Executable, expression.ClauseElement): > """Base class for DDL expression constructs.""" > > _execution_options = expression.Executable.\ > _execution_options.union({'autocommit':True}) > > In my nose test against postgresql, I emit a bunch of DDL, perform the test > and then roll back the whole shebang which conveniently makes it look like I > didn't touch the database. Obviously, the emitted commits were getting in my > way, so I wrote this: > > class NoCommitDDL(DDL): > def __init__(self,*args,**kw): > super(NoCommitDDL,self).__init__(*args,**kw) > unfrozen = dict(self._execution_options) > del unfrozen['autocommit'] > self._execution_options = frozendict(unfrozen) > > DDL = NoCommitDDL > > I still feel like I am missing something though. I understand that PostgreSQL > is perhaps one of few databases to allow for transaction-aware DDL, but why > is a commit emitted for the DDL for any database, when the database makes it > implied anyway?
Several databases offer transactional DDL including Postgresql. SQLA doesn't differentiate between these backends - it emits COMMIT after any statement that it considers to be an "autocommit" statement. "autocommit" means, "commit this statement after completion, if a transaction is not in progress". >From this it follows that if you'd like to emit several DDL statements in a >transaction, the usage is no different for DDL expressions than for any other >kind of DML statement (i.e insert/update/delete). Use >connection.begin()/transaction.commit() as documented at: http://www.sqlalchemy.org/docs/core/connections.html#using-transactions . autocommit is described right after that: http://www.sqlalchemy.org/docs/core/connections.html#understanding-autocommit Also the public API for _execution_options is the execution_options() generative call: http://www.sqlalchemy.org/docs/core/expression_api.html?highlight=execution_options#sqlalchemy.sql.expression.Executable.execution_options . -- 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.