Beispiel #1
0
def enable_sqlite_savepoints(engine):
    """ Savepoint support for sqlite.

    https://code.google.com/p/pysqlite-static-env/
    """
    from sqlalchemy import event

    @event.listens_for(engine, 'connect')
    def connect(dbapi_connection, connection_record):
        dbapi_connection.operation_needs_transaction_callback = lambda x: True

    from zope.sqlalchemy.datamanager import NO_SAVEPOINT_SUPPORT
    NO_SAVEPOINT_SUPPORT.discard('sqlite')
Beispiel #2
0
# See https://code.google.com/p/pysqlite-static-env/
HAS_PATCHED_PYSQLITE = False
if engine.url.drivername == 'sqlite':
    try:
        from pysqlite2.dbapi2 import Connection
    except ImportError:
        pass
    else:
        if hasattr(Connection, 'operation_needs_transaction_callback'):
            HAS_PATCHED_PYSQLITE = True

if HAS_PATCHED_PYSQLITE:
    from sqlalchemy import event
    from zope.sqlalchemy.datamanager import NO_SAVEPOINT_SUPPORT
    NO_SAVEPOINT_SUPPORT.remove('sqlite')

    @event.listens_for(engine, 'connect')
    def connect(dbapi_connection, connection_record):
        dbapi_connection.operation_needs_transaction_callback = lambda x: True


Session = orm.scoped_session(
    orm.sessionmaker(
        bind=engine,
        extension=tx.ZopeTransactionExtension(),
        twophase=TEST_TWOPHASE,
    ))

UnboundSession = orm.scoped_session(
    orm.sessionmaker(
Beispiel #3
0
# See https://code.google.com/p/pysqlite-static-env/
HAS_PATCHED_PYSQLITE = False
if engine.url.drivername == 'sqlite':
    try:
        from pysqlite2.dbapi2 import Connection
    except ImportError:
        pass
    else:
        if hasattr(Connection, 'operation_needs_transaction_callback'):
            HAS_PATCHED_PYSQLITE = True

if HAS_PATCHED_PYSQLITE:
    from sqlalchemy import event
    from zope.sqlalchemy.datamanager import NO_SAVEPOINT_SUPPORT
    NO_SAVEPOINT_SUPPORT.remove('sqlite')

    @event.listens_for(engine, 'connect')
    def connect(dbapi_connection, connection_record):
        dbapi_connection.operation_needs_transaction_callback = lambda x: True


Session = orm.scoped_session(orm.sessionmaker(
    bind=engine,
    extension=tx.ZopeTransactionExtension(),
    twophase=TEST_TWOPHASE,
))

UnboundSession = orm.scoped_session(orm.sessionmaker(
    extension=tx.ZopeTransactionExtension(),
    twophase=TEST_TWOPHASE,
Beispiel #4
0
# See https://code.google.com/p/pysqlite-static-env/
HAS_PATCHED_PYSQLITE = False
if engine.url.drivername == "sqlite":
    try:
        from pysqlite2.dbapi2 import Connection
    except ImportError:
        pass
    else:
        if hasattr(Connection, "operation_needs_transaction_callback"):
            HAS_PATCHED_PYSQLITE = True

if HAS_PATCHED_PYSQLITE:
    from sqlalchemy import event
    from zope.sqlalchemy.datamanager import NO_SAVEPOINT_SUPPORT

    NO_SAVEPOINT_SUPPORT.remove("sqlite")

    @event.listens_for(engine, "connect")
    def connect(dbapi_connection, connection_record):
        dbapi_connection.operation_needs_transaction_callback = lambda x: True


Session = orm.scoped_session(
    orm.sessionmaker(bind=engine, twophase=TEST_TWOPHASE))
tx.register(Session)

UnboundSession = orm.scoped_session(orm.sessionmaker(twophase=TEST_TWOPHASE))
tx.register(UnboundSession)

EventSession = orm.scoped_session(
    orm.sessionmaker(bind=engine, twophase=TEST_TWOPHASE))