Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Apr 28, 2016
1 parent ec6eee8 commit f7428c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/SQLParser/Node/NodeFactory.php
Expand Up @@ -620,15 +620,16 @@ public static function simplify($nodes)
*/

if (isset(self::$OPERATOR_TO_CLASS[$operation]) && is_subclass_of(self::$OPERATOR_TO_CLASS[$operation], 'SQLParser\Node\AbstractTwoOperandsOperator')) {
if (count($operands) != 2) {
throw new MagicQueryException('An error occured while parsing SQL statement. Invalid character found next to "'.$operation.'"');
}

$leftOperand = array_shift($operands);
while (!empty($operands)) {
$rightOperand = array_shift($operands);
$rightOperand = array_shift($operands);

$instance = new self::$OPERATOR_TO_CLASS[$operation]();
$instance->setLeftOperand($leftOperand);
$instance->setRightOperand($rightOperand);
$leftOperand = $instance;
}
$instance = new self::$OPERATOR_TO_CLASS[$operation]();
$instance->setLeftOperand($leftOperand);
$instance->setRightOperand($rightOperand);

return $instance;
} elseif (isset(self::$OPERATOR_TO_CLASS[$operation]) && is_subclass_of(self::$OPERATOR_TO_CLASS[$operation], 'SQLParser\Node\AbstractManyInstancesOperator')) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Mouf/Database/MagicQueryTest.php
Expand Up @@ -116,6 +116,16 @@ public function testInNullException() {
$magicQuery->build($sql, ['statuses' => NULL]);
}

/**
* @expectedException \Mouf\Database\MagicQueryException
*/
public function testInvalidSql() {
$magicQuery = new MagicQuery();

$sql = 'SELECT * FROM users WHERE date_end => :startDate';
$this->assertEquals('SELECT * FROM users WHERE date_end => \'2014-06-06\'', self::simplifySql($magicQuery->build($sql, ['startDate' => '2014-06-06'])));
}

public function testWithCache()
{
global $db_url;
Expand Down

0 comments on commit f7428c2

Please sign in to comment.