Skip to content

Commit

Permalink
[Tests] Truncated SQLite last insert ID to real DB integer value (#421)
Browse files Browse the repository at this point in the history
For more details see #421
  • Loading branch information
alongosz authored Aug 26, 2024
1 parent e8e81c8 commit b106a2a
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ final class SqliteGateway implements Gateway
*/
private const FATAL_ERROR_CODE = 7;

private const DB_INT_MAX = 2147483647;

/** @var array<string, int> */
private $lastInsertedIds = [];

Expand All @@ -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;
Expand Down

0 comments on commit b106a2a

Please sign in to comment.