Skip to content

Use JDBCType.NULL for null if possible #2069

New issue

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

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

Already on GitHub? # to your account

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

Conversation

schauder
Copy link
Contributor

@schauder schauder commented Jun 4, 2025

This is based on #2068.

Not all databases support the JDBCSqlType.NULL.
Therefore this handling was made dialect dependent, with SQL Server and DB2 using the old approach, while all others use JDBCSqlType.NULL

In the process modified AbstractJdbcConfiguration to use JdbcDialect instead of Dialect.

Closes #1935

schauder and others added 5 commits June 4, 2025 15:15
Signed-off-by: Sergey Korotaev <sergey.evgen.kor2501@gmail.com>

Original pull request #2068
Closes #1935
Improved naming and formatting

Original pull request #2068
See #1935
Not all databases support the JDBCSqlType.NULL.
Therefore this handling was made dialect dependent, with SQL Server and DB2 using the old approach, while all others use JDBCSqlType.NULL

In the process modified AbstractJdbcConfiguration to use JdbcDialect instead of Dialect.

Original pull request #2068
See #1935
See #2031
Remove unused fields in TestConfiguration.

Original pull request #2068
See #1935
* Implementation that always uses {@link JDBCType#NULL}. Suitable for all databases that actually support this
* {@link JDBCType}.
*/
NullTypeStrategy DEFAULT = sqlType -> JDBCType.NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have more meaningful names. Something like NULL_VALUE instead of DEFAULT

Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure this is the best way to approach the problem because we're introducing configuration complexity on our side how to massage the JDBC driver.

In R2DBC, we've solved the issue of writing null values by considering these in the SQL statement using NULL instead of a parameter bind marker. That seems much easier than figuring out (and potentially asking the database to obtain) a SQL type number for a null value.

* {@link SQLType} to use for {@literal null} values.
*
* @param sqlType a fallback value that is considered suitable by the caller.
* @return Guaranteed not to be {@literal null}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving a null Postgres enum results in a varchar value
3 participants