1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

DATE_ADD - Support for seconds

This commit is contained in:
FabioBatSilva 2015-02-25 14:32:51 -05:00
parent 1369cdda2b
commit 57bcd7cd3d
2 changed files with 24 additions and 1 deletions

View file

@ -45,6 +45,12 @@ class DateAddFunction extends FunctionNode
public function getSql(SqlWalker $sqlWalker) public function getSql(SqlWalker $sqlWalker)
{ {
switch (strtolower($this->unit->value)) { switch (strtolower($this->unit->value)) {
case 'second':
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddSecondsExpression(
$this->firstDateExpression->dispatch($sqlWalker),
$this->intervalExpression->dispatch($sqlWalker)
);
case 'hour': case 'hour':
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression( return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression(
$this->firstDateExpression->dispatch($sqlWalker), $this->firstDateExpression->dispatch($sqlWalker),
@ -64,7 +70,7 @@ class DateAddFunction extends FunctionNode
default: default:
throw QueryException::semanticalError( throw QueryException::semanticalError(
'DATE_ADD() only supports units of type hour, day and month.' 'DATE_ADD() only supports units of type second, hour, day and month.'
); );
} }
} }

View file

@ -300,6 +300,23 @@ class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertTrue(strtotime($arg[0]['add']) > 0); $this->assertTrue(strtotime($arg[0]['add']) > 0);
} }
public function testDateAddSecond()
{
$dql = "SELECT CURRENT_TIMESTAMP() now, DATE_ADD(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m";
$query = $this->_em->createQuery($dql)->setMaxResults(1);
$result = $query->getArrayResult();
$this->assertCount(1, $result);
$this->assertArrayHasKey('now', $result[0]);
$this->assertArrayHasKey('add', $result[0]);
$now = strtotime($result[0]['now']);
$add = strtotime($result[0]['add']);
$diff = $add - $now;
$this->assertSQLEquals(10, $diff);
}
/** /**
* @group DDC-1014 * @group DDC-1014
*/ */