Skip to content

Commit b106a2a

Browse files
authored
[Tests] Truncated SQLite last insert ID to real DB integer value (#421)
For more details see #421
1 parent e8e81c8 commit b106a2a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib/Persistence/Legacy/SharedGateway/DatabasePlatform/SqliteGateway.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ final class SqliteGateway implements Gateway
1818
*/
1919
private const FATAL_ERROR_CODE = 7;
2020

21+
private const DB_INT_MAX = 2147483647;
22+
2123
/** @var array<string, int> */
2224
private $lastInsertedIds = [];
2325

@@ -27,7 +29,7 @@ public function getColumnNextIntegerValue(
2729
string $sequenceName
2830
): ?int {
2931
$lastId = $this->lastInsertedIds[$sequenceName] ?? 0;
30-
$nextId = (int)hrtime(true);
32+
$nextId = (int)hrtime(true) % self::DB_INT_MAX;
3133

3234
// $lastId === $nextId shouldn't happen using high-resolution time, but better safe than sorry
3335
return $this->lastInsertedIds[$sequenceName] = $lastId === $nextId ? $nextId + 1 : $nextId;

0 commit comments

Comments
 (0)