1
0
mirror of synced 2024-12-05 03:06:05 +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)
{
switch (strtolower($this->unit->value)) {
case 'second':
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddSecondsExpression(
$this->firstDateExpression->dispatch($sqlWalker),
$this->intervalExpression->dispatch($sqlWalker)
);
case 'hour':
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression(
$this->firstDateExpression->dispatch($sqlWalker),
@ -64,7 +70,7 @@ class DateAddFunction extends FunctionNode
default:
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);
}
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
*/