From 411862d5d83f259def10f9a6edb5976755df4a8f Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 2 Nov 2015 14:48:22 +0100 Subject: [PATCH] DibiFluent: fixed combination of modifier and inner fluent [Closes #192] --- dibi/libs/DibiFluent.php | 6 ++++-- tests/dibi/DibiFluent.select.phpt | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dibi/libs/DibiFluent.php b/dibi/libs/DibiFluent.php index d13bff76..1f3554ca 100644 --- a/dibi/libs/DibiFluent.php +++ b/dibi/libs/DibiFluent.php @@ -175,7 +175,10 @@ class DibiFluent extends DibiObject implements IDataSource } elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier $args = array('%n', $arg); - } elseif (is_array($arg) || ($arg instanceof Traversable && !$arg instanceof self)) { // any array + } elseif ($arg instanceof self) { + $args = array('%SQL', $arg); + + } elseif (is_array($arg) || $arg instanceof Traversable) { // any array if (isset(self::$modifiers[$clause])) { $args = array(self::$modifiers[$clause], $arg); @@ -187,7 +190,6 @@ class DibiFluent extends DibiObject implements IDataSource foreach ($args as $arg) { if ($arg instanceof self) { - $this->cursor[] = '%SQL'; $arg = "($arg)"; } $this->cursor[] = $arg; diff --git a/tests/dibi/DibiFluent.select.phpt b/tests/dibi/DibiFluent.select.phpt index 95c573e5..dd9a4a7c 100644 --- a/tests/dibi/DibiFluent.select.phpt +++ b/tests/dibi/DibiFluent.select.phpt @@ -141,3 +141,12 @@ Assert::same( reformat('SELECT * FROM [me] AS [t] WHERE col > 10 AND ([x] = \'a\') AND (b) AND (c)'), (string) $fluent ); + + +$fluent = $conn->select('*')->from('abc') + ->where('x IN (%SQL)', $conn->select('id')->from('xyz')); + +Assert::same( + reformat('SELECT * FROM [abc] WHERE x IN ((SELECT [id] FROM [xyz]))'), + (string) $fluent +);