Skip to content

Commit

Permalink
Merge pull request #50 from moufmouf/case_in_where
Browse files Browse the repository at this point in the history
Case statement in where condition is removed by magic parameters
  • Loading branch information
moufmouf committed Jul 17, 2019
2 parents 91dda2c + e1b88d4 commit e6c267f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/SQLParser/Node/Expression.php
Expand Up @@ -33,6 +33,7 @@
namespace SQLParser\Node;

use Doctrine\DBAL\Connection;
use function is_iterable;
use Mouf\MoufInstanceDescriptor;
use Mouf\MoufManager;
use SQLParser\Node\Traverser\NodeTraverser;
Expand Down Expand Up @@ -263,10 +264,14 @@ public function walk(VisitorInterface $visitor)
*/
public function canBeBypassed(array $parameters): bool
{
foreach ($this->subTree as $node) {
if (!$node instanceof BypassableInterface || !$node->canBeBypassed($parameters)) {
return false;
if (is_iterable($this->subTree)) {
foreach ($this->subTree as $node) {
if (!$node instanceof BypassableInterface || !$node->canBeBypassed($parameters)) {
return false;
}
}
} elseif (!$this->subTree instanceof BypassableInterface || !$this->subTree->canBeBypassed($parameters)) {
return false;
}
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Mouf/Database/MagicQueryTest.php
Expand Up @@ -177,6 +177,9 @@ public function testStandardSelect()

$sql = 'SELECT a FROM users u, users u2';
$this->assertEquals('SELECT a FROM users AS u CROSS JOIN users AS u2', self::simplifySql($magicQuery->build($sql)));

$sql = 'SELECT a FROM users u WHERE status = (CASE WHEN u.id = 1 THEN u.status_1 ELSE u.status_2 END)';
$this->assertEquals('SELECT a FROM users AS u WHERE status = (CASE WHEN u.id = 1 THEN u.status_1 ELSE u.status_2 END)', self::simplifySql($magicQuery->build($sql)));
}

/**
Expand Down

0 comments on commit e6c267f

Please sign in to comment.