compile

  1. drupal
    1. drupal7
Versionen
drupal7 public DatabaseCondition::compile(DatabaseConnection $connection)

Verwandte Themen

Code

includes/database/query.inc, line 1120

<?php
public function compile(DatabaseConnection $connection) {
  // This value is static, so it will increment across the entire request
  // rather than just this query. That is OK, because we only need definitive
  // placeholder names if we're going to use them for _alter hooks, which we
  // are not. The alter hook would intervene before compilation.
  // $next_placeholder does not use drupal_static as it increments and should
  // never be reset during a request.
  static $next_placeholder = 1;

  if ($this->changed) {

    $condition_fragments = array();
    $arguments = array();

    $conditions = $this->conditions;
    $conjunction = $conditions['#conjunction'];
    unset($conditions['#conjunction']);
    foreach ($conditions as $condition) {
      if (empty($condition['operator'])) {
        // This condition is a literal string, so let it through as is.
        $condition_fragments[] = ' (' . $condition['field'] . ') ';
        $arguments += $condition['value'];
      }
      else {
        // It's a structured condition, so parse it out accordingly.
        if ($condition['field'] instanceof QueryConditionInterface) {
          // Compile the sub-condition recursively and add it to the list.
          $condition['field']->compile($connection);
          $condition_fragments[] = '(' . (string) $condition['field'] . ')';
          $arguments += $condition['field']->arguments();
        }
        else {
          // For simplicity, we treat all operators as the same data structure.
          // In the typical degenerate case, this won't get changed.
          $operator_defaults = array(
              'prefix' => '',
              'postfix' => '',
              'delimiter' => '',
              'operator' => $condition['operator'],
              'use_value' => TRUE,
            );
          $operator = $connection->mapConditionOperator($condition['operator']);
          if (!isset($operator)) {
            $operator = $this->mapConditionOperator($condition['operator']);
          }
          $operator += $operator_defaults;

          if ($condition['value'] instanceof SelectQuery) {
            $placeholders[] = (string) $condition['value'];
            $arguments += $condition['value']->arguments();
          }
          // We assume that if there is a delimiter, then the value is an
          // array. If not, it is a scalar. For simplicity, we first convert
          // up to an array so that we can build the placeholders in the same way.
          elseif (!$operator['delimiter']) {
            $condition['value'] = array($condition['value']);
          }
          $placeholders = array();
          if ($operator['use_value']) {
            foreach ($condition['value'] as $value) {
              $placeholder = ':db_condition_placeholder_' . $next_placeholder++;
              $arguments[$placeholder] = $value;
              $placeholders[] = $placeholder;
            }
          }
          $condition_fragments[] = ' (' . $condition['field'] . ' ' . $operator['operator'] . ' ' . $operator['prefix'] . implode($operator['delimiter'], $placeholders) . $operator['postfix'] . ') ';

        }
      }
    }

    $this->changed = FALSE;
    $this->stringVersion = implode($conjunction, $condition_fragments);
    $this->arguments = $arguments;
  }
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen