Skip to content

Commit 8b93b40

Browse files
Update Dockerfile and refactor BIGINT handling in database adapters
- Added bcmath extension to Dockerfile for improved numeric handling. - Changed return type of getLimitForBigInt method to string across Adapter, Mongo, Pool, and SQL classes. - Updated maxBigIntLength parameter in Attribute class to string for consistency in validation logic. - Enhanced validation logic to use bccomp for BIGINT size comparisons.
1 parent b5c7447 commit 8b93b40

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ RUN apk update && apk add --no-cache \
4444
&& cd / \
4545
&& rm -rf /tmp/mongodb)) \
4646
&& docker-php-ext-enable mongodb \
47-
&& docker-php-ext-install opcache pgsql pdo_mysql pdo_pgsql \
47+
&& docker-php-ext-install bcmath opcache pgsql pdo_mysql pdo_pgsql \
4848
&& apk del libpq-dev \
4949
&& rm -rf /var/cache/apk/*
5050

src/Database/Adapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,9 @@ abstract public function getLimitForInt(): int;
883883
/**
884884
* Get max BIGINT limit
885885
*
886-
* @return int
886+
* @return string
887887
*/
888-
abstract public function getLimitForBigInt(): int;
888+
abstract public function getLimitForBigInt(): string;
889889

890890
/**
891891
* Get maximum attributes limit.

src/Database/Adapter/Mongo.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,12 +3009,12 @@ public function getLimitForInt(): int
30093009
/**
30103010
* Get max BIGINT limit
30113011
*
3012-
* @return int
3012+
* @return string
30133013
*/
3014-
public function getLimitForBigInt(): int
3014+
public function getLimitForBigInt(): string
30153015
{
30163016
// Mongo does not handle integers directly, so using MariaDB limit for now
3017-
return 18446744073709551615;
3017+
return '18446744073709551615';
30183018
}
30193019

30203020
/**

src/Database/Adapter/Pool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public function getLimitForInt(): int
328328
return $this->delegate(__FUNCTION__, \func_get_args());
329329
}
330330

331-
public function getLimitForBigInt(): int
331+
public function getLimitForBigInt(): string
332332
{
333333
return $this->delegate(__FUNCTION__, \func_get_args());
334334
}

src/Database/Adapter/SQL.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,14 @@ public function getLimitForInt(): int
899899
/**
900900
* Get max BIGINT limit
901901
*
902-
* @return int
902+
* @return float|int
903903
*/
904-
public function getLimitForBigInt(): int
904+
public function getLimitForBigInt(): string
905905
{
906906
// 2^64 - 1
907907
// 18446744073709551615 is the maximum value for a 64-bit unsigned integer
908908
// 9223372036854775807 is the maximum value for a 64-bit signed integer
909-
return 18446744073709551615;
909+
return '18446744073709551615';
910910
}
911911

912912
/**

src/Database/Validator/Attribute.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Attribute extends Validator
3131
* @param int $maxStringLength
3232
* @param int $maxVarcharLength
3333
* @param int $maxIntLength
34-
* @param int $maxBigIntLength
34+
* @param string $maxBigIntLength
3535
* @param bool $supportForSchemaAttributes
3636
* @param bool $supportForVectors
3737
* @param bool $supportForSpatialAttributes
@@ -50,7 +50,7 @@ public function __construct(
5050
protected int $maxStringLength = 0,
5151
protected int $maxVarcharLength = 0,
5252
protected int $maxIntLength = 0,
53-
protected int $maxBigIntLength = 0,
53+
protected string $maxBigIntLength = '',
5454
protected bool $supportForSchemaAttributes = false,
5555
protected bool $supportForVectors = false,
5656
protected bool $supportForSpatialAttributes = false,
@@ -345,9 +345,12 @@ public function checkType(Document $attribute): bool
345345
break;
346346

347347
case Database::VAR_BIGINT:
348-
$limit = ($signed) ? $this->maxBigIntLength / 2 : $this->maxBigIntLength;
349-
if ($size > $limit) {
350-
$this->message = 'Max size allowed for bigint is: ' . number_format($limit);
348+
$limit = $signed
349+
? bcdiv($this->maxBigIntLength, '2', 0)
350+
: $this->maxBigIntLength;
351+
352+
if (bccomp((string)$size, $limit) === 1) {
353+
$this->message = 'Max size allowed for bigint is: ' . number_format((float)$limit);
351354
throw new DatabaseException($this->message);
352355
}
353356
break;

0 commit comments

Comments
 (0)