Skip to content

Commit 655c072

Browse files
committed
Handle bits/sign
1 parent 43505a1 commit 655c072

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Database/Validator/Query/Filter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ protected function isValidAttributeAndValues(string $attribute, array $values, s
146146
break;
147147

148148
case Database::VAR_INTEGER:
149-
$validator = new Integer();
149+
$size = $attributeSchema['size'] ?? 4;
150+
$signed = $attributeSchema['signed'] ?? true;
151+
$bits = $size >= 8 ? 64 : 32;
152+
// For 64-bit unsigned, use signed since PHP doesn't support true 64-bit unsigned
153+
$unsigned = !$signed && $bits < 64;
154+
$validator = new Integer(false, $bits, $unsigned);
150155
break;
151156

152157
case Database::VAR_FLOAT:

src/Database/Validator/Structure.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,12 @@ protected function checkForInvalidAttributeValues(array $structure, array $keys)
348348
break;
349349

350350
case Database::VAR_INTEGER:
351-
// We need both Integer and Range because Range implicitly casts non-numeric values
352-
$validators[] = new Integer();
351+
// Determine bit size based on attribute size in bytes
352+
$bits = $size >= 8 ? 64 : 32;
353+
// For 64-bit unsigned, use signed since PHP doesn't support true 64-bit unsigned
354+
// The Range validator will restrict to positive values only
355+
$unsigned = !$signed && $bits < 64;
356+
$validators[] = new Integer(false, $bits, $unsigned);
353357
$max = $size >= 8 ? Database::MAX_BIG_INT : Database::MAX_INT;
354358
$min = $signed ? -$max : 0;
355359
$validators[] = new Range($min, $max, Database::VAR_INTEGER);

0 commit comments

Comments
 (0)