Skip to content

Commit

Permalink
🐛 bugfix/#6261 - Allow (also for DATETIME) dynamic intervals in DATE_…
Browse files Browse the repository at this point in the history
…ADD & DATE_SUB for SQLite

- 🐛 Fix code divergence
- ✅ Add related tests
  • Loading branch information
DaedalusDev committed Jan 12, 2024
1 parent 6a793fb commit 843719c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Platforms/SqlitePlatform.php
Expand Up @@ -152,6 +152,10 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv
case DateIntervalUnit::SECOND:
case DateIntervalUnit::MINUTE:
case DateIntervalUnit::HOUR:
if (! is_numeric($interval)) {
$interval = "' || " . $interval . " || '";
}

return 'DATETIME(' . $date . ",'" . $operator . $interval . ' ' . $unit . "')";
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Platforms/SqlitePlatformTest.php
Expand Up @@ -733,6 +733,22 @@ public function testQuotesDropForeignKeySQL(): void
$this->markTestSkipped('SQLite does not support altering foreign key constraints.');
}

public function testDateAddStaticNumberOfMinutes(): void
{
self::assertSame(
"DATETIME(endAt,'+12 MINUTE')",
$this->platform->getDateAddMinutesExpression('endAt', 12),
);
}

public function testDateAddNumberOfMinutesFromColumn(): void
{
self::assertSame(
"DATETIME(endAt,'+' || duration || ' MINUTE')",
$this->platform->getDateAddMinutesExpression('endAt', 'duration'),
);
}

public function testDateAddStaticNumberOfDays(): void
{
self::assertSame(
Expand Down

0 comments on commit 843719c

Please sign in to comment.