def do_(query, ec=None, args=None):
    """
    Execute a query
    """
    from time import time
    from uliweb.utils.common import get_caller

    conn = get_session(ec)
    b = time()
    result = conn.execute(query, *(args or ()))
    t = time() - b
    dispatch.call(ec, 'post_do', query, conn, t)
    
    flag = False
    sql = ''
    if hasattr(Local, 'echo') and Local.echo:
        if hasattr(Local, 'echo_args'):
            _ec = Local.echo_args.get('session')
        else:
            _ec = None
        engine_name = get_engine_name(ec)
        _e = get_engine_name(_ec)
        
        if not _ec or _ec and _ec == _e:
            if hasattr(Local, 'echo_args') and Local.echo_args['time']:
                if t >= Local.echo_args['time']:
                    sql = rawsql(query)
                    
                    flag = True
            else:
                sql = rawsql(query)
                flag = True
        
        if flag:
            print '\n===>>>>> [%s]' % engine_name,
            if hasattr(Local, 'echo_args') and Local.echo_args['caller']:
                v = get_caller(skip=__file__)
                print '(%s:%d:%s)' % v
            else:
                print
            print sql+';'
            if hasattr(Local, 'echo_args') and Local.echo_args['explain'] and sql:
                r = conn.execute('explain '+sql).fetchone()
                print '\n----\nExplain: %s' % ''.join(["%s=%r, " % (k, v) for k, v in r.items()])
            print '===<<<<< time used %fs\n' % t
                
    return result
Execute a query