fix!: EXPOSED-360 Storing ULong.MAX_VALUE in ulong column not working #2068
+49
−23
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.
The issue:
When attempting to store
ULong.MAX_VALUE
in aulong
column, retrieving it results in -1 and notULong.MAX_VALUE
for all database dialects (except for MySQL and MariaDB). The reason is that we invoke.toLong()
on theULong
value before we store it in the database (innotNullValueToDB
inULongColumnType
) and that gets the -1 from here because of the implementation ofULong.toLong()
.The fix:
Before this fix, the maximum value that could be stored with
ULongColumnType
for all database dialects (except for MySQL and MariaDB) wasLong.MAX_VALUE
. This is because theULong
value was being converted toLong
in thenotNullValueToDB
function, restricting the range to that ofLong
. Instead, it is now converted to aBigInteger
for PostgreSQL, aLong
for PostgreSQLNG (with a range check), and aString
for the rest of the database dialects. Theulong
column can now storeULong.MAX_VALUE
for H2 (excluding H2_PSQL), Oracle, SQLite and SQL Server.Breaking change:
ulongType()
is now NUMERIC(20) instead of BIGINT for H2 (excluding H2_PSQL), SQLite, and SQL Server to allow storing the full range ofULong
, includingULong.MAX_VALUE
.Limitations:
ulongType()
to NUMERIC(20) because that would cause a mismatch when it references an auto-incrementing ulong column of type BIGSERIAL. It's also not possible to change theautoIncType
to NUMERIC(20) either, because PostgreSQL does not support the AUTO_INCREMENT property. So the maximum value that can be stored isLong.MAX_VALUE
.ulong
auto-increment column is the same as that of along
column.