Skip to content

Commit

Permalink
Merge pull request #3019 from fogs/date_add
Browse files Browse the repository at this point in the history
Allow dynamic intervals in DATE_ADD & DATE_SUB for SQLite
  • Loading branch information
morozov committed Mar 29, 2018
2 parents 792c5b5 + 968e6a5 commit a4015c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Expand Up @@ -150,6 +150,10 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv
break;
}

if (! is_numeric($interval)) {
$interval = "' || " . $interval . " || '";
}

return "DATE(" . $date . ",'" . $operator . $interval . " " . $unit . "')";
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
Expand Up @@ -749,4 +749,14 @@ public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
}

public function testDateAddStaticNumberOfDays()
{
self::assertSame("DATE(rentalBeginsOn,'+12 DAY')", $this->_platform->getDateAddDaysExpression('rentalBeginsOn', 12));
}

public function testDateAddNumberOfDaysFromColumn()
{
self::assertSame("DATE(rentalBeginsOn,'+' || duration || ' DAY')", $this->_platform->getDateAddDaysExpression('rentalBeginsOn', 'duration'));
}
}

0 comments on commit a4015c8

Please sign in to comment.