Skip to content

Commit

Permalink
Fixed last errors related to identifier quoting in postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 21, 2014
1 parent e9de0fa commit b345d80
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions src/Database/IdentifierQuoter.php
Expand Up @@ -19,6 +19,7 @@
use Cake\Database\Expression\Comparison;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Database\Expression\OrderByExpression;
use Cake\Database\ExpressionInterface;

/**
* Contains all the logic related to quoting identifiers in a Query object
Expand Down Expand Up @@ -59,25 +60,32 @@ public function quote(Query $query) {
$this->_quoteParts($query);
}

$query->traverseExpressions(function($expression) {
if ($expression instanceof Comparison) {
$this->_quoteComparison($expression);
return;
}
$query->traverseExpressions([$this, 'quoteExpression']);
$query->valueBinder($binder);
return $query;
}

if ($expression instanceof OrderByExpression) {
$this->_quoteOrderBy($expression);
return;
}
/**
* Quotes identifiers inside expression objects
*
* @param \Cake\Database\ExpressionInterface $expression
* @return void
*/
public function quoteExpression($expression) {
if ($expression instanceof Comparison) {
$this->_quoteComparison($expression);
return;
}

if ($expression instanceof IdentifierExpression) {
$this->_quoteIndetifierExpression($expression);
return;
}
});
if ($expression instanceof OrderByExpression) {
$this->_quoteOrderBy($expression);
return;
}

$query->valueBinder($binder);
return $query;
if ($expression instanceof IdentifierExpression) {
$this->_quoteIndetifierExpression($expression);
return;
}
}

/**
Expand Down Expand Up @@ -176,13 +184,20 @@ protected function _quoteComparison(Comparison $expression) {
$field = $expression->getField();
if (is_string($field)) {
$expression->field($this->_driver->quoteIdentifier($field));
}
if (is_array($field)) {
} elseif (is_array($field)) {
$quoted = [];
foreach ($field as $f) {
$quoted[] = $this->_driver->quoteIdentifier($f);
}
$expression->field($quoted);
} elseif ($field instanceof ExpressionInterface) {
$expression->field($this->quoteExpression($field));
}

$value = $expression->getValue();
if ($value instanceof ExpressionInterface) {
$this->quoteExpression($value);
$expression->value($value);
}
}

Expand Down

0 comments on commit b345d80

Please sign in to comment.