Skip to content

[Lock] Fix using fractional TTLs #61085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Symfony/Component/Lock/Store/DoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ private function getCurrentTimestampStatement(): string
$platform = $this->conn->getDatabasePlatform();

return match (true) {
$platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform,
$platform instanceof \Doctrine\DBAL\Platforms\MySQL57Platform => 'UNIX_TIMESTAMP()',
$platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform => 'strftime(\'%s\',\'now\')',
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform,
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform => 'CAST(EXTRACT(epoch FROM NOW()) AS INT)',
$platform instanceof \Doctrine\DBAL\Platforms\OraclePlatform => '(SYSDATE - TO_DATE(\'19700101\',\'yyyymmdd\'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone), 1, 3))*3600',
$platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform,
$platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform => 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())',
default => (string) time(),
$platform instanceof \Doctrine\DBAL\Platforms\MySQL57Platform,
$platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform => 'UNIX_TIMESTAMP(NOW(6))',
$platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform => "(julianday('now') - 2440587.5) * 86400.0",
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform,
$platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform => 'CAST(EXTRACT(epoch FROM NOW()) AS DOUBLE PRECISION)',
$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'))",
$platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform,
$platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform => "CAST(DATEDIFF_BIG(ms, '1970-01-01', SYSUTCDATETIME()) AS FLOAT) / 1000.0",
default => (new \DateTimeImmutable())->format('U.u'),
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Lock/Store/PdoStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ private function getDriver(): string
private function getCurrentTimestampStatement(): string
{
return match ($this->getDriver()) {
'mysql' => 'UNIX_TIMESTAMP()',
'sqlite' => 'strftime(\'%s\',\'now\')',
'pgsql' => 'CAST(EXTRACT(epoch FROM NOW()) AS INT)',
'oci' => '(SYSDATE - TO_DATE(\'19700101\',\'yyyymmdd\'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone), 1, 3))*3600',
'sqlsrv' => 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())',
default => (string) time(),
'mysql' => 'UNIX_TIMESTAMP(NOW(6))',
'sqlite' => "(julianday('now') - 2440587.5) * 86400.0",
'pgsql' => 'CAST(EXTRACT(epoch FROM NOW()) AS DOUBLE PRECISION)',
'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'))",
'sqlsrv' => "CAST(DATEDIFF_BIG(ms, '1970-01-01', SYSUTCDATETIME()) AS FLOAT) / 1000.0",
default => (new \DateTimeImmutable())->format('U.u'),
};
}

Expand Down
Loading