Skip to content
Permalink
Browse files

Avoid double parenthesis when nesting functions and query expressions

  • Loading branch information...
raul338 committed Nov 6, 2017
1 parent 27166a6 commit a8306cd11d9319188c3d179e704c8f10ef16fb82
@@ -168,7 +168,7 @@ public function sql(ValueBinder $generator)
$parts = [];
foreach ($this->_conditions as $condition) {
if ($condition instanceof ExpressionInterface) {
$condition = sprintf('(%s)', $condition->sql($generator));
$condition = sprintf('%s', $condition->sql($generator));
} elseif (is_array($condition)) {
$p = $generator->placeholder('param');
$generator->bind($p, $condition['value'], $condition['type']);
@@ -14,6 +14,7 @@
namespace Cake\Test\TestCase\Database\Expression;
use Cake\Database\Expression\FunctionExpression;
use Cake\Database\Expression\QueryExpression;
use Cake\Database\ValueBinder;
use Cake\TestSuite\TestCase;
@@ -81,6 +82,20 @@ public function testFunctionNesting()
$this->assertEquals('Wrapper(bar, (MyFunction(:param0, :param1)))', $g->sql($binder));
}
/**
* Tests to avoid regression, prevents double parenthesis
* In particular nesting with QueryExpression
*
* @return void
*/
public function testFunctionNestingQueryExpression()
{
$binder = new ValueBinder;
$q = new QueryExpression('a');
$f = new FunctionExpression('MyFunction', [$q]);
$this->assertEquals('MyFunction(a)', $f->sql($binder));
}
/**
* Tests that it is possible to use a number as a literal in a function.
*

0 comments on commit a8306cd

Please sign in to comment.
You can’t perform that action at this time.