forked from beberlei/DoctrineExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Oracle CEIL/FLOOR functions + TO_CHAR nlsparam (beberlei#336)
- Loading branch information
1 parent
fa9aab0
commit fccc6a9
Showing
9 changed files
with
185 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Query\Oracle; | ||
|
||
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | ||
use Doctrine\ORM\Query\Lexer; | ||
|
||
/** | ||
* @author Jefferson Vantuir <[email protected]> | ||
*/ | ||
class Ceil extends FunctionNode | ||
{ | ||
private $number; | ||
|
||
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) | ||
{ | ||
return sprintf( | ||
'CEIL(%s)', | ||
$sqlWalker->walkArithmeticPrimary($this->number) | ||
); | ||
} | ||
|
||
public function parse(\Doctrine\ORM\Query\Parser $parser) | ||
{ | ||
$parser->match(Lexer::T_IDENTIFIER); | ||
$parser->match(Lexer::T_OPEN_PARENTHESIS); | ||
$this->number = $parser->ArithmeticExpression(); | ||
$parser->match(Lexer::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,30 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Query\Oracle; | ||
|
||
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | ||
use Doctrine\ORM\Query\Lexer; | ||
|
||
/** | ||
* @author Jefferson Vantuir <[email protected]> | ||
*/ | ||
class Floor extends FunctionNode | ||
{ | ||
private $number; | ||
|
||
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) | ||
{ | ||
return sprintf( | ||
'FLOOR(%s)', | ||
$sqlWalker->walkArithmeticPrimary($this->number) | ||
); | ||
} | ||
|
||
public function parse(\Doctrine\ORM\Query\Parser $parser) | ||
{ | ||
$parser->match(Lexer::T_IDENTIFIER); | ||
$parser->match(Lexer::T_OPEN_PARENTHESIS); | ||
$this->number = $parser->ArithmeticExpression(); | ||
$parser->match(Lexer::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
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,32 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Tests\Entities; | ||
|
||
/** | ||
* @Entity | ||
*/ | ||
class Product | ||
{ | ||
/** @Id @Column(type="string") @GeneratedValue */ | ||
public $id; | ||
|
||
/** | ||
* @Column(type="string") | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @Column(type="DateTime") | ||
*/ | ||
public $created; | ||
|
||
/** | ||
* @Column(type="decimal", precision=10, scale=2) | ||
*/ | ||
public $price; | ||
|
||
/** | ||
* @Column(type="decimal", precision=5, scale=2) | ||
*/ | ||
public $weight; | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Tests\Query\Oracle; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
use DoctrineExtensions\Tests\Entities\Product; | ||
use DoctrineExtensions\Tests\Query\OracleTestCase; | ||
|
||
/** | ||
* @author Jefferson Vantuir <[email protected]> | ||
*/ | ||
class CeilTest extends OracleTestCase | ||
{ | ||
public function testFullQuery() | ||
{ | ||
$queryBuilder = new QueryBuilder($this->entityManager); | ||
$queryBuilder->select('CEIL(p.weight)') | ||
->from(Product::class, 'p'); | ||
|
||
$sql = 'SELECT CEIL(p0_.weight) AS sclr_0 FROM Product p0_'; | ||
$this->assertEquals($sql, $queryBuilder->getQuery()->getSQL()); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Tests\Query\Oracle; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
use DoctrineExtensions\Tests\Entities\Product; | ||
use DoctrineExtensions\Tests\Query\OracleTestCase; | ||
|
||
/** | ||
* @author Jefferson Vantuir <[email protected]> | ||
*/ | ||
class FloorTest extends OracleTestCase | ||
{ | ||
public function testFullQuery() | ||
{ | ||
$queryBuilder = new QueryBuilder($this->entityManager); | ||
$queryBuilder->select('FLOOR(p.weight)') | ||
->from(Product::class, 'p'); | ||
|
||
$sql = 'SELECT FLOOR(p0_.weight) AS sclr_0 FROM Product p0_'; | ||
$this->assertEquals($sql, $queryBuilder->getQuery()->getSQL()); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Tests\Query\Oracle; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
use DoctrineExtensions\Tests\Entities\Date; | ||
use DoctrineExtensions\Tests\Query\OracleTestCase; | ||
|
||
/** | ||
* @author Jefferson Vantuir <[email protected]> | ||
*/ | ||
class ToCharTest extends OracleTestCase | ||
{ | ||
public function testFullQuery() | ||
{ | ||
$queryBuilder = new QueryBuilder($this->entityManager); | ||
$queryBuilder->select('TO_CHAR(d.created, \'DD-MON-YYYY HH24:MI:SSxFF\', \'german\')') | ||
->from(Date::class, 'd'); | ||
|
||
$sql = 'SELECT TO_CHAR(d0_.created, \'DD-MON-YYYY HH24:MI:SSxFF\', \'german\') AS sclr_0 FROM Date d0_'; | ||
$this->assertEquals($sql, $queryBuilder->getQuery()->getSQL()); | ||
} | ||
} |