You are here

function views_plugin_query_default::build in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 7.3 plugins/views_plugin_query_default.inc \views_plugin_query_default::build()

Builds the necessary info to execute the query.

Overrides views_plugin_query::build

File

plugins/views_plugin_query_default.inc, line 1119
views_plugin_query_default.inc Defines the default query object which builds SQL to execute using the Drupal database API.

Class

views_plugin_query_default
Object used to create a SELECT query.

Code

function build(&$view) {

  // Make the query distinct if the option was set.
  if (!empty($this->options['distinct'])) {
    $this
      ->set_distinct();
  }

  // Store the view in the object to be able to use it later.
  $this->view = $view;
  $view
    ->init_pager();

  // Let the pager modify the query to add limits.
  $this->pager
    ->query();
  $this->query = $this
    ->query();
  if (empty($this->options['disable_sql_rewrite'])) {
    $this->final_query = db_rewrite_sql($this->query, $view->base_table, $view->base_field, array(
      'view' => &$view,
    ));
    $this->count_query = db_rewrite_sql($this
      ->query(TRUE), $view->base_table, $view->base_field, array(
      'view' => &$view,
    ));
  }
  else {
    $this->final_query = $this->query;
    $this->count_query = $this
      ->query(TRUE);
  }
  $this->query_args = $this
    ->get_where_args();
}