public function SelectQuery::preExecute

7.x public SelectQuery::preExecute(SelectQueryInterface $query = NULL)

Generic preparation and validation for a SELECT query.

Return value

TRUE if the validation was successful, FALSE if not.

Overrides SelectQueryInterface::preExecute

1 call to SelectQuery::preExecute()
SelectQuery::execute in drupal/includes/database/
Runs the query against the database.


drupal/includes/database/, line 1221


Query builder for SELECT statements.


public function preExecute(SelectQueryInterface $query = NULL) {
  // If no query object is passed in, use $this.
  if (!isset($query)) {
    $query = $this;

  // Only execute this once.
  if ($query->isPrepared()) {
    return TRUE;

  // Modules may alter all queries or only those having a particular tag.
  if (isset($this->alterTags)) {
    $hooks = array('query');
    foreach ($this->alterTags as $tag => $value) {
      $hooks[] = 'query_' . $tag;
    drupal_alter($hooks, $query);

  $this->prepared = TRUE;

  // Now also prepare any sub-queries.
  foreach ($this->tables as $table) {
    if ($table['table'] instanceof SelectQueryInterface) {

  foreach ($this->union as $union) {

  return $this->prepared;