def rollback_unlock_tables(session): """Rollback and unlock tables supported backends: MySQL and PostgreSQL """ session.rollback() # unlock if is_mysql(): session.execute('UNLOCK TABLES')
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')
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()
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)
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))