that is absolutely the reason transactions would not be working for you. autocommit on the DBAPI essentially makes the commit() and rollback() methods of the DBAPI connection a no-op.
On Jan 18, 2011, at 5:12 AM, bool wrote: > I have put a self contained script that can probably reproduce this > for you. I think that the argument 'connect_args': {'autocommit' : > True } is causing the transactions to not work properly. Is this > expected and if so can you explain the reason. Thanks in advance. > > > > ==================================================================================================================== > from sqlalchemy import * > from sqlalchemy.sql import * > > > def main(): > """ > Main body of the script. > """ > > meta = MetaData() > kwargs = { > 'echo' : True, > 'module_name' : 'pyodbc', > 'connect_args': {'autocommit' : True }, > } > engine = create_engine("mssql://login:password@/database? > driver=FreeTDS&dsn=DBDEV", **kwargs) > connection = engine.connect() > meta.bind = engine > > table = Table("bbb", meta, Column('id', Integer, > primary_key=True), Column('name', String), > Column('tt_start', Date, primary_key=True), > Column('tt_end', Date, primary_key=True), > Column('vt_start', Date, primary_key=True), > Column('vt_end', Date, primary_key=True)) > table.create() > > for row in connection.execute(select([table])): > print row > > trans = connection.begin() > try: > ins = table.insert().values(id=122, name='k', > tt_start='20100101', tt_end='20100101', vt_start='20100101', > vt_end='20100101') > > connection.execute(ins) > ins = table.insert().values(id=121, name='k') > connection.execute(ins) > trans.commit() > except: > trans.rollback() > for row in connection.execute(select([table])): > print row > raise > > > if __name__ == "__main__": > main() > > -- > 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.