public function DatabaseCondition::compile

cis7 query.inc public DatabaseCondition::compile(DatabaseConnection $connection, QueryPlaceholderInterface $queryPlaceholder)
cle7 query.inc public DatabaseCondition::compile(DatabaseConnection $connection, QueryPlaceholderInterface $queryPlaceholder)
elmsmedia7 query.inc public DatabaseCondition::compile(DatabaseConnection $connection, QueryPlaceholderInterface $queryPlaceholder)
icor7 query.inc public DatabaseCondition::compile(DatabaseConnection $connection, QueryPlaceholderInterface $queryPlaceholder)
meedjum_blog7 query.inc public DatabaseCondition::compile(DatabaseConnection $connection, QueryPlaceholderInterface $queryPlaceholder)
mooc7 query.inc public DatabaseCondition::compile(DatabaseConnection $connection, QueryPlaceholderInterface $queryPlaceholder)

Implements QueryConditionInterface::compile().

Overrides QueryConditionInterface::compile

File

includes/database/query.inc, line 1793
Non-specific Database query code. Used by all engines.

Class

DatabaseCondition
Generic class for a series of conditions in a query.

Code

public function compile(DatabaseConnection $connection, QueryPlaceholderInterface $queryPlaceholder) {
  // Re-compile if this condition changed or if we are compiled against a
  // different query placeholder object.
  if ($this->changed || isset($this->queryPlaceholderIdentifier) && ($this->queryPlaceholderIdentifier != $queryPlaceholder->uniqueIdentifier())) {
    $this->queryPlaceholderIdentifier = $queryPlaceholder->uniqueIdentifier();

    $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.
        // Note that $condition['field'] will only be an object for a dependent
        // DatabaseCondition object, not for a dependent subquery.
        if ($condition['field'] instanceof QueryConditionInterface) {
          // Compile the sub-condition recursively and add it to the list.
          $condition['field']->compile($connection, $queryPlaceholder);
          $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;

          $placeholders = array();
          if ($condition['value'] instanceof SelectQueryInterface) {
            $condition['value']->compile($connection, $queryPlaceholder);
            $placeholders[] = (string) $condition['value'];
            $arguments += $condition['value']->arguments();
            // Subqueries are the actual value of the operator, we don't
            // need to add another below.
            $operator['use_value'] = FALSE;
          }
          // 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']);
          }
          if ($operator['use_value']) {
            foreach ($condition['value'] as $value) {
              $placeholder = ':db_condition_placeholder_' . $queryPlaceholder->nextPlaceholder();
              $arguments[$placeholder] = $value;
              $placeholders[] = $placeholder;
            }
          }
          $condition_fragments[] = ' (' . $connection->escapeField($condition['field']) . ' ' . $operator['operator'] . ' ' . $operator['prefix'] . implode($operator['delimiter'], $placeholders) . $operator['postfix'] . ') ';
        }
      }
    }

    $this->changed = FALSE;
    $this->stringVersion = implode($conjunction, $condition_fragments);
    $this->arguments = $arguments;
  }
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.