Exemplo n.º 1
0
def rollback_unlock_tables(session):
    """Rollback and unlock tables

    supported backends: MySQL and PostgreSQL
    """
    session.rollback()

    # unlock
    if is_mysql():
        session.execute('UNLOCK TABLES')
Exemplo n.º 2
0
def commit_unlock_tables(session):
    """Commit and unlock tables for supported backends: MySQL and PostgreSQL"""
    session.commit()
    session.execute('COMMIT')  # execute COMMIT on DB backend
    # because sqlalchemy session does not guarantee
    # exact boundary correspondence to DB backend transactions
    # We must guarantee DB commits transaction before UNLOCK

    # unlock
    if is_mysql():
        session.execute('UNLOCK TABLES')
Exemplo n.º 3
0
def rollback_unlock_tables(session):
    """Rollback and unlock tables

    supported backends: MySQL and PostgreSQL
    """
    # unlock
    if is_mysql():
        session.execute('UNLOCK TABLES')

    # postgres automatically releases lock at transaction end

    session.rollback()
Exemplo n.º 4
0
def rollback_unlock_tables(session):
    """Rollback and unlock tables

    supported backends: MySQL and PostgreSQL
    """
    # unlock
    if is_mysql():
        session.execute('UNLOCK TABLES')

    # postgres automatically releases lock at transaction end

    session.rollback()
Exemplo n.º 5
0
def commit_unlock_tables(session):
    """Commit and unlock tables for supported backends: MySQL and PostgreSQL"""
    try:
        session.execute('COMMIT')  # execute COMMIT on DB backend
        session.commit()
        # because sqlalchemy session does not guarantee
        # exact boundary correspondence to DB backend transactions
        # We must guarantee DB commits transaction before UNLOCK

        # unlock
        if is_mysql():
            session.execute('UNLOCK TABLES')
        # postgres automatically releases lock at transaction end
    except db_exc.DBDataError as exc:
        LOG.exception('Database backend experienced data error.')
        raise congress_exc.DatabaseDataError(data=exc)
Exemplo n.º 6
0
def commit_unlock_tables(session):
    """Commit and unlock tables for supported backends: MySQL and PostgreSQL"""
    try:
        session.execute('COMMIT')  # execute COMMIT on DB backend
        session.commit()
        # because sqlalchemy session does not guarantee
        # exact boundary correspondence to DB backend transactions
        # We must guarantee DB commits transaction before UNLOCK

        # unlock
        if is_mysql():
            session.execute('UNLOCK TABLES')
        # postgres automatically releases lock at transaction end
    except db_exc.DBDataError as exc:
        LOG.exception('Database backend experienced data error.')
        raise congress_exc.DatabaseDataError(data=exc)
Exemplo n.º 7
0
def lock_tables(session, tables):
    """Write-lock tables for supported backends: MySQL and PostgreSQL"""
    session.begin(subtransactions=True)
    if is_mysql():  # Explicitly LOCK TABLES for MySQL
        session.execute('SET autocommit=0')
        session.execute('LOCK TABLES {}'.format(
            ','.join([table + ' WRITE' for table in tables])))
    elif is_postgres():  # Explicitly LOCK TABLE for Postgres
        session.execute('BEGIN TRANSACTION')
        for table in tables:
            session.execute('LOCK TABLE {} IN EXCLUSIVE MODE'.format(table))
Exemplo n.º 8
0
def lock_tables(session, tables):
    """Write-lock tables for supported backends: MySQL and PostgreSQL"""
    session.begin(subtransactions=True)
    if is_mysql():  # Explicitly LOCK TABLES for MySQL
        session.execute('SET autocommit=0')
        session.execute('LOCK TABLES {}'.format(
            ','.join([table + ' WRITE' for table in tables])))
    elif is_postgres():  # Explicitly LOCK TABLE for Postgres
        session.execute('BEGIN TRANSACTION')
        for table in tables:
            session.execute('LOCK TABLE {} IN EXCLUSIVE MODE'.format(table))