Skip to content

Commit

Permalink
Merge pull request #65 from GitHubHubus/ceil_function
Browse files Browse the repository at this point in the history
added CEIL function
  • Loading branch information
x86demon authored Sep 27, 2019
2 parents 9373fde + 3dea007 commit 2dbedcc
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Available functions:
* `YEAR(expr)` - Return the year from the date passed
* `POW(expr, power)` - Return the argument raised to the specified power
* `ROUND(value, ?precision)` - Return the value formated with the (optional) specified precision
* `CEIL(value)` - Return the value rounded up
* `SIGN(expr)` - Return the sign of the argument
* `CAST(expr as type)` - Takes an expression of any type and produces a result value of a specified type. Supported types are: "char, string, text, date, datetime, time, int, integer, decimal, boolean, binary"
* `CONCAT_WS` - Concatenate all but the first argument with separators. The first argument is used as the separator string.
Expand Down Expand Up @@ -144,6 +145,7 @@ doctrine:
sign: Oro\ORM\Query\AST\Functions\Numeric\Sign
pow: Oro\ORM\Query\AST\Functions\Numeric\Pow
round: Oro\ORM\Query\AST\Functions\Numeric\Round
ceil: Oro\ORM\Query\AST\Functions\SimpleFunction
string_functions:
md5: Oro\ORM\Query\AST\Functions\SimpleFunction
group_concat: Oro\ORM\Query\AST\Functions\String\GroupConcat
Expand Down Expand Up @@ -202,6 +204,7 @@ for [dflydev/dflydev-doctrine-orm-service-provider](https://github.com/dflydev/d
'sign' => 'Oro\ORM\Query\AST\Functions\Numeric\Sign',
'pow' => 'Oro\ORM\Query\AST\Functions\Numeric\Pow',
'round' => 'Oro\ORM\Query\AST\Functions\Numeric\Round',
'ceil' => 'Oro\ORM\Query\AST\Functions\SimpleFunction',
]
]);
```
Expand Down Expand Up @@ -236,6 +239,7 @@ return [
'sign' => 'Oro\ORM\Query\AST\Functions\Numeric\Sign',
'pow' => 'Oro\ORM\Query\AST\Functions\Numeric\Pow',
'round' => 'Oro\ORM\Query\AST\Functions\Numeric\Round',
'ceil' => 'Oro\ORM\Query\AST\Functions\SimpleFunction',
],
'string_functions' => [
'md5' => 'Oro\ORM\Query\AST\Functions\SimpleFunction',
Expand Down
20 changes: 20 additions & 0 deletions src/Oro/ORM/Query/AST/Platform/Functions/Mysql/Ceil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Oro\ORM\Query\AST\Platform\Functions\Mysql;

use Oro\ORM\Query\AST\Functions\SimpleFunction;
use Oro\ORM\Query\AST\Platform\Functions\PlatformFunctionNode;
use Doctrine\ORM\Query\SqlWalker;

class Ceil extends PlatformFunctionNode
{
/**
* {@inheritdoc}
*/
public function getSql(SqlWalker $sqlWalker)
{
$value = $this->parameters[SimpleFunction::PARAMETER_KEY];

return sprintf('CEIL(%s)', $this->getExpressionValue($value, $sqlWalker));
}
}
20 changes: 20 additions & 0 deletions src/Oro/ORM/Query/AST/Platform/Functions/Postgresql/Ceil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Oro\ORM\Query\AST\Platform\Functions\Postgresql;

use Oro\ORM\Query\AST\Functions\SimpleFunction;
use Oro\ORM\Query\AST\Platform\Functions\PlatformFunctionNode;
use Doctrine\ORM\Query\SqlWalker;

class Ceil extends PlatformFunctionNode
{
/**
* {@inheritdoc}
*/
public function getSql(SqlWalker $sqlWalker)
{
$value = $this->parameters[SimpleFunction::PARAMETER_KEY];

return sprintf('CEIL(%s)', $this->getExpressionValue($value, $sqlWalker));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- functions:
- { name: "ceil", className: "Oro\\ORM\\Query\\AST\\Functions\\SimpleFunction", type: "numeric" }
dql: "SELECT CEIL(12.34) FROM Oro\\Entities\\Foo f WHERE f.id = 1"
sql: "SELECT CEIL(12.34) AS sclr0 FROM test_foo t0_ WHERE t0_.id = 1"
expectedResult:
- 13
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- functions:
- { name: "ceil", className: "Oro\\ORM\\Query\\AST\\Functions\\SimpleFunction", type: "numeric" }
dql: "SELECT CEIL(12.34) FROM Oro\\Entities\\Foo f WHERE f.id = 1"
sql: "SELECT CEIL(12.34) AS sclr0 FROM test_foo t0_ WHERE t0_.id = 1"
expectedResult:
- 13

0 comments on commit 2dbedcc

Please sign in to comment.