Commit 58b03f35 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Fix Oracle testfailures and problem with Date Diff calculation

parent ffff175c
...@@ -100,9 +100,20 @@ class OraclePlatform extends AbstractPlatform ...@@ -100,9 +100,20 @@ class OraclePlatform extends AbstractPlatform
return 'SYS_GUID()'; return 'SYS_GUID()';
} }
/**
* Get the number of days difference between two dates.
*
* Note: Since Oracle timestamp differences are calculated down to the microsecond we have to truncate
* them to the difference in days. This is obviously a restriction of the original functionality, but we
* need to make this a portable function.
*
* @param type $date1
* @param type $date2
* @return type
*/
public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
{ {
return '('.$date1 . '-'.$date2.')'; return "TRUNC(TO_NUMBER(SUBSTR((" . $date1 . "-" . $date2 . "), 1, INSTR(" . $date1 . "-" . $date2 .", ' '))))";
} }
public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
......
...@@ -252,7 +252,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -252,7 +252,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
{ {
$p = $this->_conn->getDatabasePlatform(); $p = $this->_conn->getDatabasePlatform();
$sql = 'SELECT '; $sql = 'SELECT ';
$sql .= $p->getDateDiffExpression('test_datetime', "'2010-12-24 12:00:00'") .' AS diff, '; $sql .= $p->getDateDiffExpression('test_datetime', $p->getCurrentTimestampSQL()) .' AS diff, ';
$sql .= $p->getDateAddDaysExpression('test_datetime', 10) .' AS add_days, '; $sql .= $p->getDateAddDaysExpression('test_datetime', 10) .' AS add_days, ';
$sql .= $p->getDateSubDaysExpression('test_datetime', 10) .' AS sub_days, '; $sql .= $p->getDateSubDaysExpression('test_datetime', 10) .' AS sub_days, ';
$sql .= $p->getDateAddMonthExpression('test_datetime', 2) .' AS add_month, '; $sql .= $p->getDateAddMonthExpression('test_datetime', 2) .' AS add_month, ';
...@@ -260,8 +260,10 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -260,8 +260,10 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sql .= 'FROM fetch_table'; $sql .= 'FROM fetch_table';
$row = $this->_conn->fetchAssoc($sql); $row = $this->_conn->fetchAssoc($sql);
$row = array_change_key_case($row, CASE_LOWER);
$this->assertEquals(-357, (int)$row['diff'], "Date difference should be -356 days."); $diff = floor( (strtotime('2010-01-01')-time()) / 3600 / 24);
$this->assertEquals($diff, (int)$row['diff'], "Date difference should be approx. ".$diff." days.", 1);
$this->assertEquals('2010-01-11', date('Y-m-d', strtotime($row['add_days'])), "Adding date should end up on 2010-01-11"); $this->assertEquals('2010-01-11', date('Y-m-d', strtotime($row['add_days'])), "Adding date should end up on 2010-01-11");
$this->assertEquals('2009-12-22', date('Y-m-d', strtotime($row['sub_days'])), "Subtracting date should end up on 2009-12-22"); $this->assertEquals('2009-12-22', date('Y-m-d', strtotime($row['sub_days'])), "Subtracting date should end up on 2009-12-22");
$this->assertEquals('2010-03-01', date('Y-m-d', strtotime($row['add_month'])), "Adding month should end up on 2010-03-01"); $this->assertEquals('2010-03-01', date('Y-m-d', strtotime($row['add_month'])), "Adding month should end up on 2010-03-01");
......
...@@ -32,7 +32,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -32,7 +32,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
return array( return array(
'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)', 'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)',
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL)", "ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL)",
"ALTER TABLE mytable DROP COLUMN foo", "ALTER TABLE mytable DROP (foo)",
"ALTER TABLE mytable RENAME TO userlist", "ALTER TABLE mytable RENAME TO userlist",
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment