fix: Use ResultSet.getObject
to respect nullable columns of the basic SQL data types
#22
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.
Description
Use
ResultSet.getObject
for the generation code of sqlc-gen-kotlin to respect nullable columns of the basic SQL data types.Fixes #20
Details
java.sql.ResultSet.get{SpecificType}
, such asResultSet.getInt
,ResultSet.getBoolean
, returns the zero value of each types when the selected value is SQL NULL.https://docs.oracle.com/en/java/javase/21/docs/api/java.sql/java/sql/ResultSet.html#getBoolean(int)
On the other hand,
ResultSet.getObject
returns null when the selected value is SQL NULL.https://docs.oracle.com/en/java/javase/21/docs/api/java.sql/java/sql/ResultSet.html#getObject(int,java.lang.Class)
Both pgjdbc/PgResultSet.getObject, mysql-connector-j/ResultSetImpl.getObject implements
ResultSet.getObject
with nullable column handling and basic SQL data types detection, so I think sqlc-gen-kotlin should be use it and rely on driver implementations.Appendix