1.20.x select.inc public SelectQuery::addExpression($expression, $alias = NULL, $arguments = array())

Implements SelectQueryInterface::addExpression().

Overrides SelectQueryInterface::addExpression

File

includes/database/select.inc, line 1503

Class

SelectQuery
Query builder for SELECT statements.

Code

public function addExpression($expression, $alias = NULL, $arguments = array()) {
  if (empty($alias)) {
    $alias = 'expression';
  }

  $alias_candidate = $alias;
  $count = 2;
  while (!empty($this->expressions[$alias_candidate])) {
    $alias_candidate = $alias . '_' . $count++;
  }
  $alias = $alias_candidate;

  $this->expressions[$alias] = array(
    'expression' => $expression,
    'alias' => $alias,
    'arguments' => $arguments,
  );

  return $alias;
}