Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: EXPOSED-360 Storing ULong.MAX_VALUE in ulong column not working #2068

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joc-a
Copy link
Collaborator

@joc-a joc-a commented Apr 30, 2024

The issue:

When attempting to store ULong.MAX_VALUE in a ulong column, retrieving it results in -1 and not ULong.MAX_VALUE for all database dialects (except for MySQL and MariaDB). The reason is that we invoke .toLong() on the ULong value before we store it in the database (in notNullValueToDB in ULongColumnType) and that gets the -1 from here because of the implementation of ULong.toLong().

The fix:

Before this fix, the maximum value that could be stored with ULongColumnType for all database dialects (except for MySQL and MariaDB) was Long.MAX_VALUE. This is because the ULong value was being converted to Long in the notNullValueToDB function, restricting the range to that of Long. Instead, it is now converted to a BigInteger for PostgreSQL, a Long for PostgreSQLNG (with a range check), and a String for the rest of the database dialects. The ulong column can now store ULong.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 of ULong, including ULong.MAX_VALUE.

Limitations:

  • For PostgreSQL, it is not possible to change 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 the autoIncType to NUMERIC(20) either, because PostgreSQL does not support the AUTO_INCREMENT property. So the maximum value that can be stored is Long.MAX_VALUE.
  • For SQLite, it is not possible to have auto-increment on a column of type other than INTEGER PRIMARY KEY, so the maximum value that can be stored using a ulong auto-increment column is the same as that of a long column.

@joc-a joc-a requested review from bog-walk and e5l April 30, 2024 16:06
@joc-a joc-a force-pushed the joc/exposed-360 branch 3 times, most recently from 0742540 to 00a0cfb Compare April 30, 2024 19:48
@joc-a joc-a marked this pull request as draft April 30, 2024 19:52
@joc-a
Copy link
Collaborator Author

joc-a commented Apr 30, 2024

@e5l @bog-walk I want to run more tests on some corner cases with references before I merge this, so you can ignore this PR for now.

@joc-a joc-a force-pushed the joc/exposed-360 branch 3 times, most recently from d246ec4 to 942c654 Compare April 30, 2024 22:29
@joc-a joc-a changed the title fix!: EXPOSED-360 Storing ULong.MAX_VALUE in ulong column not working fix!: Storing ULong.MAX_VALUE in ulong column not working for SQL Server May 1, 2024
@joc-a joc-a changed the title fix!: Storing ULong.MAX_VALUE in ulong column not working for SQL Server fix!: Storing ULong.MAX_VALUE in ulong column not working May 1, 2024
@joc-a joc-a force-pushed the joc/exposed-360 branch 2 times, most recently from 74a7416 to fc50ff2 Compare May 1, 2024 10:14
Before this fix, the maximum value that could be stored with `ULongColumnType` for all database dialects was `Long.MAX_VALUE`. This is because the `ULong` value was being converted to `Long` in the `notNullValueToDB` function, restricting the range to that of `Long`. Instead, it is now converted to a `Long` only for PostgreSQL, and a `String` for the rest of the database dialects. For PostgreSQL, it is not possible to store a value greater than `Long.MAX_VALUE` at the moment. This is because it's not possible to have an auto-increment column of the same type NUMERIC(20), and having different types for `ulongType()` and `ulongAutoincType()` will cause a crash when one references the other. This will be solved in another pull request.

Breaking change: `ulongType()` is now NUMERIC(20) instead of BIGINT for H2, SQL Server, and SQLite, to allow storing the full range of `ULong`.
@joc-a joc-a changed the title fix!: Storing ULong.MAX_VALUE in ulong column not working fix!: EXPOSED-360 Storing ULong.MAX_VALUE in ulong column not working May 22, 2024
@joc-a joc-a marked this pull request as ready for review May 22, 2024 08:20
@joc-a
Copy link
Collaborator Author

joc-a commented May 22, 2024

Ready for review @bog-walk @e5l

@joc-a joc-a requested a review from obabichevjb May 23, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant