Пример #1
0
def view_results(request, id, first_row=0, last_result_len=0):
  """
  Returns the view for the results of the QueryHistory with the given id.

  The query results MUST be ready.
  To display query results, one should always go through the watch_query view.

  If ``first_row`` is 0, restarts (if necessary) the query read.  Otherwise, just
  spits out a warning if first_row doesn't match the servers conception.
  Multiple readers will produce a confusing interaction here, and that's known.

  It understands the ``context`` GET parameter. (See watch_query().)
  """
  # Coerce types; manage arguments
  id = int(id)
  first_row = long(first_row)
  start_over = (first_row == 0)

  query_history = authorized_get_history(request, id, must_exist=True)

  handle = QueryHandle(id=query_history.server_id, log_context=query_history.log_context)
  context = _parse_query_context(request.GET.get('context'))

  # Retrieve query results
  try:
    results = db_utils.db_client(query_history.get_query_server()).fetch(handle, start_over, -1)
    assert results.ready, _('Trying to display result that is not yet ready. Query id %(id)s') % {'id': id}
    # We display the "Download" button only when we know
    # that there are results:
    downloadable = (first_row > 0 or len(results.data) > 0)
    fetch_error = False
  except BeeswaxException, ex:
    fetch_error = True
    error_message, log = expand_exception(ex)
Пример #2
0
def execute_query(request, design_id=None, table=None):
  authorized_get_design(request, design_id)
  error_message, log = None, None
  form = query_form()
  action = request.path
  design = safe_get_design(request, SavedQuery.HQL, design_id)
  on_success_url = request.REQUEST.get('on_success_url')

  for _ in range(1):
    if request.method == 'POST':
      form.bind(request.POST)
      to_explain = request.POST.has_key('button-explain')
      to_submit = request.POST.has_key('button-submit')
      # Always validate the saveform, which will tell us whether it needs explicit saving
      if not form.is_valid():
        break
      to_save = form.saveform.cleaned_data['save']
      to_saveas = form.saveform.cleaned_data['saveas']
      if to_saveas and not design.is_auto:
        # Save As only affects a previously saved query
        design = design.clone()
      if to_submit or to_save or to_saveas or to_explain:
        explicit_save = to_save or to_saveas
        design = save_design(request, form, SavedQuery.HQL, design, explicit_save)
        action = urlresolvers.reverse(execute_query, kwargs=dict(design_id=design.id))

      # We're not going to process the form. Simply re-render it.
      if not to_explain and not to_submit:
        break

      query_str = _strip_trailing_semicolon(form.query.cleaned_data["query"])
      query_server = db_utils.get_query_server(form.query_servers.cleaned_data["server"])
      # (Optional) Parameterization.
      parameterization = get_parameterization(request, query_str, form, design, to_explain)
      if parameterization:
        return parameterization

      query_msg = make_beeswax_query(request, query_str, form)
      try:
        if to_explain:
          return expl_d(request, query_str, query_msg, design, query_server)
        else:
          notify = form.query.cleaned_data.get('email_notify', False)
          return e_d(request, query_msg, design=design,
            on_success_url=on_success_url,
            notify=notify)
      except BeeswaxException, ex:
        error_message, log = expand_exception(ex)
        # Fall through to re-render the execute form.
    else:
      # GET request
      if design.id is not None:
        data = HQLdesign.loads(design.data).get_query_dict()
        form.bind(data)
        form.saveform.set_data(design.name, design.desc)
      else:
        # New design
        form.bind()
Пример #3
0
def read_table(request, table):
  """View function for select * from table"""
  table_obj = db_utils.meta_client().get_table("default", table)
  hql = "SELECT * FROM `%s` %s" % (table, _get_browse_limit_clause(table_obj))
  query_msg = make_beeswax_query(request, hql)
  try:
    return execute_directly(request, query_msg, tablename=table)
  except BeeswaxException, e:
    # Note that this state is difficult to get to.
    error_message, log = expand_exception(e)
    error = _("Failed to read table. Error: %(error)s") % {'error': error_message}
    raise PopupException(error, title=_("Beeswax Error"), detail=log)
Пример #4
0
def read_table(request, table):
    """View function for select * from table"""
    table_obj = db_utils.meta_client().get_table("default", table)
    hql = "SELECT * FROM `%s` %s" % (table,
                                     _get_browse_limit_clause(table_obj))
    query_msg = make_beeswax_query(request, hql)
    try:
        return execute_directly(request, query_msg, tablename=table)
    except BeeswaxException, e:
        # Note that this state is difficult to get to.
        error_message, log = expand_exception(e)
        error = _("Failed to read table. Error: %(error)s") % {
            'error': error_message
        }
        raise PopupException(error, title=_("Beeswax Error"), detail=log)
Пример #5
0
def view_results(request, id, first_row=0, last_result_len=0):
    """
  Returns the view for the results of the QueryHistory with the given id.

  The query results MUST be ready.
  To display query results, one should always go through the watch_query view.

  If ``first_row`` is 0, restarts (if necessary) the query read.  Otherwise, just
  spits out a warning if first_row doesn't match the servers conception.
  Multiple readers will produce a confusing interaction here, and that's known.

  It understands the ``context`` GET parameter. (See watch_query().)
  """
    # Coerce types; manage arguments
    id = int(id)
    first_row = long(first_row)
    start_over = (first_row == 0)

    query_history = authorized_get_history(request, id, must_exist=True)

    handle = QueryHandle(id=query_history.server_id,
                         log_context=query_history.log_context)
    context = _parse_query_context(request.GET.get('context'))

    # Retrieve query results
    try:
        results = db_utils.db_client(query_history.get_query_server()).fetch(
            handle, start_over, -1)
        assert results.ready, _(
            'Trying to display result that is not yet ready. Query id %(id)s'
        ) % {
            'id': id
        }
        # We display the "Download" button only when we know
        # that there are results:
        downloadable = (first_row > 0 or len(results.data) > 0)
        fetch_error = False
    except BeeswaxException, ex:
        fetch_error = True
        error_message, log = expand_exception(ex)
Пример #6
0
def execute_query(request, design_id=None, table=None):
    authorized_get_design(request, design_id)
    error_message, log = None, None
    form = query_form()
    action = request.path
    design = safe_get_design(request, SavedQuery.HQL, design_id)
    on_success_url = request.REQUEST.get('on_success_url')

    for _ in range(1):
        if request.method == 'POST':
            form.bind(request.POST)
            to_explain = request.POST.has_key('button-explain')
            to_submit = request.POST.has_key('button-submit')
            # Always validate the saveform, which will tell us whether it needs explicit saving
            if not form.is_valid():
                break
            to_save = form.saveform.cleaned_data['save']
            to_saveas = form.saveform.cleaned_data['saveas']
            if to_saveas and not design.is_auto:
                # Save As only affects a previously saved query
                design = design.clone()
            if to_submit or to_save or to_saveas or to_explain:
                explicit_save = to_save or to_saveas
                design = save_design(request, form, SavedQuery.HQL, design,
                                     explicit_save)
                action = urlresolvers.reverse(execute_query,
                                              kwargs=dict(design_id=design.id))

            # We're not going to process the form. Simply re-render it.
            if not to_explain and not to_submit:
                break

            query_str = _strip_trailing_semicolon(
                form.query.cleaned_data["query"])
            query_server = db_utils.get_query_server(
                form.query_servers.cleaned_data["server"])
            # (Optional) Parameterization.
            parameterization = get_parameterization(request, query_str, form,
                                                    design, to_explain)
            if parameterization:
                return parameterization

            query_msg = make_beeswax_query(request, query_str, form)
            try:
                if to_explain:
                    return expl_d(request, query_str, query_msg, design,
                                  query_server)
                else:
                    notify = form.query.cleaned_data.get('email_notify', False)
                    return e_d(request,
                               query_msg,
                               design=design,
                               on_success_url=on_success_url,
                               notify=notify)
            except BeeswaxException, ex:
                error_message, log = expand_exception(ex)
                # Fall through to re-render the execute form.
        else:
            # GET request
            if design.id is not None:
                data = HQLdesign.loads(design.data).get_query_dict()
                form.bind(data)
                form.saveform.set_data(design.name, design.desc)
            else:
                # New design
                form.bind()