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: Use ResultSet.getObject to respect nullable columns of the basic SQL data types #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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
1 participant