From cc2d1193e2cd2aa34562e410ce5b722ab982695b Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Thu, 22 Aug 2024 17:44:45 +0200 Subject: [PATCH] [Tests] Truncated SQLite last insert ID to real DB integer value --- .../Legacy/SharedGateway/DatabasePlatform/SqliteGateway.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/SqliteGateway.php b/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/SqliteGateway.php index 31ed4d15bd..b92fa7ea03 100644 --- a/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/SqliteGateway.php +++ b/src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/SqliteGateway.php @@ -18,6 +18,8 @@ final class SqliteGateway implements Gateway */ private const FATAL_ERROR_CODE = 7; + private const DB_INT_MAX = 2147483647; + /** @var array */ private $lastInsertedIds = []; @@ -27,7 +29,7 @@ public function getColumnNextIntegerValue( string $sequenceName ): ?int { $lastId = $this->lastInsertedIds[$sequenceName] ?? 0; - $nextId = (int)hrtime(true); + $nextId = (int)hrtime(true) % self::DB_INT_MAX; // $lastId === $nextId shouldn't happen using high-resolution time, but better safe than sorry return $this->lastInsertedIds[$sequenceName] = $lastId === $nextId ? $nextId + 1 : $nextId;