Repository navigation
Add bUInt() and bUIntArray() for unsigned integers - #19
Merged
Merged
Conversation
- Bind 0 to 18446744073709551615 (BIGINT UNSIGNED). Negative, non-numeric and out-of-range values throw; values above PHP_INT_MAX are accepted as integer strings. - Both use '%%' and put validated digits into the SQL. A string parameter is compared as a float in MySQL expressions and IN() lists, so large neighbouring values would match. - New UnsignedNumericBindingInterface extends NumericBindingInterface; numeric bindings that don't implement it fall back to the MySQL ones. - Unit tests, plus MySQL (BIGINT UNSIGNED) and PostgreSQL (numeric(20)) integration tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
There was no way to bind unsigned integers.
bInt()accepts negative numbers and stops at PHP's integer maximum, 9223372036854775807 (2⁶³−1), so the top half of MySQL'sBIGINT UNSIGNEDcouldn't be bound.Statement::bUInt($value, $null = false)andbUIntArray(array $values)PHP_INT_MAXare passed as integer strings.InvalidArgumentException. Floats are truncated toward zero likebInt(), but floats at 2⁶³ or above are rejected because a float can't hold them exactly.bUIntArray()validates each value instead of casting it the waybIntArray()does. It removes duplicates.%%, not?. A value abovePHP_INT_MAXcan only be bound as a string. With PDO's default emulated prepares, MySQL compares a string with a number as a float in expressions andIN (...)lists, so18446744073709551615matched18446744073709551614in testing. Putting validated digits into the SQL text, asbIntArray()andbFloat()already do, is exact. Only digits pass validation, so this is safe for user input.UnsignedNumericBindingInterfacethat extendsNumericBindingInterface, andMySQLNumericBindingsimplements it. If custom numeric bindings only implement the old interface,Bindingsfalls back to the MySQL versions.bUInt()checks that a value isn't negative, and values above 2⁶³−1 need anumericcolumn.Testing
MySQLNumericBindingsTestcover valid and invalid values, arrays,getComputed()output and the fallback for custom numeric bindings.GLPDO2MySQLTest::testUnsignedBigintuses a realBIGINT UNSIGNEDcolumn. It checks exact storage and that neighbouring values don't match inid + 0 = %%andIN (%%).GLPDO2PostgreSQLTest::testUnsignedValuesAboveBigintuses anumeric(20)column.🤖 Generated with Claude Code