Skip to content

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

Closed

Description

@spring-projects-issues

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:

Activity

  1. spring-projects-issues commented on Oct 7, 2017

    @spring-projects-issues
    CollaboratorAuthor

    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.

  2. spring-projects-issues commented on Oct 7, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

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

  3. added
    type: regression
    in: data
    status: duplicate
    on Jan 11, 2019
  4. removed
    type: regression
    on Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datastatus: duplicate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions