Skip to content

Conversation

ichizero
Copy link

@ichizero ichizero commented Feb 17, 2024

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 as ResultSet.getInt, ResultSet.getBoolean, returns the zero value of each types when the selected value is SQL NULL.

"Returns: the column value; if the value is SQL NULL, the value returned is false."

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

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.

Is it a specification for sqlc that retrieving null from a nullable boolean column in Postgres results in false?
1 participant