-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Query\Oracle; | ||
|
||
use Doctrine\ORM\Query\AST\ArithmeticExpression; | ||
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | ||
use Doctrine\ORM\Query\Parser; | ||
use Doctrine\ORM\Query\SqlWalker; | ||
use Doctrine\ORM\Query\TokenType; | ||
|
||
use function sprintf; | ||
|
||
/** @author https://github.com/nxtpge */ | ||
class Nvl2 extends FunctionNode | ||
{ | ||
private ArithmeticExpression $expr1; | ||
|
||
private ArithmeticExpression $expr2; | ||
|
||
private ArithmeticExpression $expr3; | ||
|
||
public function getSql(SqlWalker $sqlWalker): string | ||
{ | ||
return sprintf( | ||
'NVL2(%s, %s, %s)', | ||
$sqlWalker->walkArithmeticExpression($this->expr1), | ||
$sqlWalker->walkArithmeticExpression($this->expr2), | ||
$sqlWalker->walkArithmeticExpression($this->expr3), | ||
); | ||
} | ||
|
||
public function parse(Parser $parser): void | ||
{ | ||
$parser->match(TokenType::T_IDENTIFIER); | ||
$parser->match(TokenType::T_OPEN_PARENTHESIS); | ||
$this->expr1 = $parser->ArithmeticExpression(); | ||
$parser->match(TokenType::T_COMMA); | ||
$this->expr2 = $parser->ArithmeticExpression(); | ||
$parser->match(TokenType::T_COMMA); | ||
$this->expr3 = $parser->ArithmeticExpression(); | ||
$parser->match(TokenType::T_CLOSE_PARENTHESIS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Tests\Query\Oracle; | ||
|
||
use DoctrineExtensions\Tests\Query\OracleTestCase; | ||
|
||
/** @author https://github.com/nxtpge */ | ||
class Nvl2Test extends OracleTestCase | ||
{ | ||
public function testNvl2(): void | ||
{ | ||
$this->assertDqlProducesSql( | ||
'SELECT NVL2(p.name, \'expr1\', \'expr2\') from DoctrineExtensions\Tests\Entities\Product p', | ||
'SELECT NVL2(p0_.name, \'expr1\', \'expr2\') AS sclr_0 FROM Product p0_' | ||
); | ||
} | ||
} |