Skip to content

Commit 93ed8fe

Browse files
bug #61085 [Lock] Fix using fractional TTLs (manuelderuiter)
This PR was merged into the 6.4 branch. Discussion ---------- [Lock] Fix using fractional TTLs Discussion ---------- Solves issue #59938 | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | n/a | License | MIT When using the PostgreSQLDBALStore with Scheduler it will cast an invalid result. Scheduler generates a TTL as float and PostgreSQL expects an integer. https://github.com/manuelderuiter/symfony_59938/actions/runs/16187766978 after the fix https://github.com/manuelderuiter/symfony_59938/actions/runs/16187926234 Commits ------- 2d329a2 [Lock] Fix using fractional TTLs on all platforms d22544c [Lock] Fixes an issue with PostgreSQL when using fractional TTLs
2 parents 6f42d09 + 2d329a2 commit 93ed8fe

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/Symfony/Component/Lock/Store/DoctrineDbalStore.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ private function getCurrentTimestampStatement(): string
254254
$platform = $this->conn->getDatabasePlatform();
255255

256256
return match (true) {
257-
$platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform,
258-
$platform instanceof \Doctrine\DBAL\Platforms\MySQL57Platform => 'UNIX_TIMESTAMP()',
259-
$platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform => 'strftime(\'%s\',\'now\')',
260-
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform,
261-
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform => 'CAST(EXTRACT(epoch FROM NOW()) AS INT)',
262-
$platform instanceof \Doctrine\DBAL\Platforms\OraclePlatform => '(SYSDATE - TO_DATE(\'19700101\',\'yyyymmdd\'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone), 1, 3))*3600',
263-
$platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform,
264-
$platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform => 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())',
265-
default => (string) time(),
257+
$platform instanceof \Doctrine\DBAL\Platforms\MySQL57Platform,
258+
$platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform => 'UNIX_TIMESTAMP(NOW(6))',
259+
$platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform => "(julianday('now') - 2440587.5) * 86400.0",
260+
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform,
261+
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform => 'CAST(EXTRACT(epoch FROM NOW()) AS DOUBLE PRECISION)',
262+
$platform instanceof \Doctrine\DBAL\Platforms\OraclePlatform => "(CAST(systimestamp AT TIME ZONE 'UTC' AS DATE) - DATE '1970-01-01') * 86400 + TO_NUMBER(TO_CHAR(systimestamp AT TIME ZONE 'UTC', 'SSSSS.FF'))",
263+
$platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform,
264+
$platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform => "CAST(DATEDIFF_BIG(ms, '1970-01-01', SYSUTCDATETIME()) AS FLOAT) / 1000.0",
265+
default => (new \DateTimeImmutable())->format('U.u'),
266266
};
267267
}
268268

src/Symfony/Component/Lock/Store/PdoStore.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ private function getDriver(): string
229229
private function getCurrentTimestampStatement(): string
230230
{
231231
return match ($this->getDriver()) {
232-
'mysql' => 'UNIX_TIMESTAMP()',
233-
'sqlite' => 'strftime(\'%s\',\'now\')',
234-
'pgsql' => 'CAST(EXTRACT(epoch FROM NOW()) AS INT)',
235-
'oci' => '(SYSDATE - TO_DATE(\'19700101\',\'yyyymmdd\'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone), 1, 3))*3600',
236-
'sqlsrv' => 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())',
237-
default => (string) time(),
232+
'mysql' => 'UNIX_TIMESTAMP(NOW(6))',
233+
'sqlite' => "(julianday('now') - 2440587.5) * 86400.0",
234+
'pgsql' => 'CAST(EXTRACT(epoch FROM NOW()) AS DOUBLE PRECISION)',
235+
'oci' => "(CAST(systimestamp AT TIME ZONE 'UTC' AS DATE) - DATE '1970-01-01') * 86400 + TO_NUMBER(TO_CHAR(systimestamp AT TIME ZONE 'UTC', 'SSSSS.FF'))",
236+
'sqlsrv' => "CAST(DATEDIFF_BIG(ms, '1970-01-01', SYSUTCDATETIME()) AS FLOAT) / 1000.0",
237+
default => (new \DateTimeImmutable())->format('U.u'),
238238
};
239239
}
240240

0 commit comments

Comments
 (0)