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

SqlTypes not propagated to database [SPR-12346] #16951

Closed
spring-projects-issues opened this issue Oct 18, 2014 · 2 comments
Closed

SqlTypes not propagated to database [SPR-12346] #16951

spring-projects-issues opened this issue Oct 18, 2014 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 18, 2014

Koen Serry opened SPR-12346 and commented

Sql types don't seem to propagate. I used a postgres backend (jdbc driver 9.3-1102-jdbc41) on a 9.3 backend. The table uses the inet type to store ip addresses.

This works in 4.0.6 while it doesn't seem to work in 4.1

MapSqlParameterSource paramSource = new MapSqlParameterSource().addValue("ip",e.getIp(),Types.OTHER,"inet");
jdbcTemplate.update("insert into addresses (ip) values (:ip)",paramSource);

Affects: 4.1.1

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Titi Wangsa Damhore commented

I think we can close this.
I tested this on 4.0.6, Spring 4.0.6 worked.
4.0.7 - 4.1.6 resulted in an SQLException
4.1.7 - 5.0.0 (latest) worked

I traced it to org.springframework.jdbc.core.StatementCreatorUtils.setValue
there is a giant if/else if/else if/.../else branch there.

the last if else and the final else triggered the bug.

the correct behaviour is to execute in the final else and have prepared statement call setObject

this is for version < 4.1.7
the last else if was
else if (sqlType == SqlTypeValue.TYPE_UNKNOWN) {
and the type passed was OTHERS, the final else was executed
ps.setObject(paramIndex, inValue, sqlType);
Result: Success

4.1.7 - 4.1.6
else if (sqlType == SqlTypeValue.TYPE_UNKNOWN || sqlType == Types.OTHER) {
since sqlType == OTHER is true, it does not go to the final else clause
and setObject was not called, setString was called.
Result -> error

4.1.7 - 5.0.0
else if (sqlType == SqlTypeValue.TYPE_UNKNOWN || (sqlType == Types.OTHER &&
"Oracle".equals(ps.getConnection().getMetaData().getDatabaseProductName()))) {
Condition is false.
final else is called.
Code works.

So. Safe to close.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 7, 2017

Juergen Hoeller commented

Thanks for double-checking! This looks like a duplicate of #17488 then, indeed fixed for 4.1.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants