Ejemplo n.º 1
0
def transfer_by_name(conn: connection, from_name: str, to_name: str,
                     amount: Union[Decimal, int]):
    try:
        transfer_by_name_impl(conn, from_name, to_name, amount)
        conn.commit()
    except MoneyAmountError:
        conn.rollback()
        raise
Ejemplo n.º 2
0
def create_transaction(conn: connection, auto_commit: bool = False) -> cursor:
    cursor = conn.cursor()
    try:
        yield cursor
    except Exception:
        logging.debug('Rolling back')
        conn.rollback()
        raise
    else:
        if auto_commit:
            logging.debug('Committing')
            conn.commit()
        else:
            logging.debug('Rolling back')
            conn.rollback()
Ejemplo n.º 3
0
def execCypher(conn:ext.connection, graphName:str, cypherStmt:str, cols:list=None, params:tuple=None) -> ext.cursor :
    if conn == None or conn.closed:
        raise _EXCEPTION_NoConnection

    stmt = buildCypher(graphName, cypherStmt, cols)
    
    cursor = conn.cursor()
    try:
        cursor.execute(stmt, params)
        return cursor
    except SyntaxError as cause:
        conn.rollback()
        raise cause
    except Exception as cause:
        conn.rollback()
        raise SqlExcutionError("Excution ERR[" + str(cause) +"](" + stmt +")", cause)
Ejemplo n.º 4
0
def execSql(conn:ext.connection, stmt:str, commit:bool=False, params:tuple=None) -> ext.cursor :
    if conn == None or conn.closed:
        raise _EXCEPTION_NoConnection
    
    cursor = conn.cursor()
    try:
        cursor.execute(stmt, params)
        if commit:
            conn.commit()
        
        return cursor
    except SyntaxError as cause:
        conn.rollback()
        raise cause
    except Exception as cause:
        conn.rollback()
        raise SqlExcutionError("Excution ERR[" + str(cause) +"](" + stmt +")", cause)