Skip to content

SqlParameterSource needs method for extracting parameter names [SPR-16361] #20908

Closed

Description

@spring-projects-issues

Philippe Marschall opened SPR-16361 and commented

NamedParameterJdbcOperations supports passing in custom implementations of SqlParameterSource. Unfortunately doing so silently breaks. The issue is that SqlParameterSource offers no way of accessing the names of the parameters so SqlParameterSourceUtils#extractCaseInsensitiveParameterNames has to cast to the implementation classes BeanPropertySqlParameterSource and MapSqlParameterSource. For any other implementation class an empty map is returned.


Affects: 5.0.2

Issue Links:

Activity

  1. spring-projects-issues commented on Jan 9, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I suppose you're using SimpleJdbcInsert and friends there? Parameter name extraction isn't needed for regular NamedParameterJdbcTemplate usage but is indeed used for matching purposes in insert and call operation objects.

  2. spring-projects-issues commented on Jan 9, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've introduced a getParameterNames() method on SqlParameterSource, with a default implementation that returns null for not determinable. Being at it, I've also added default implementations of getSqlType and getTypeName.

  3. spring-projects-issues commented on Jan 9, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Philippe Marschall commented

    Thanks for the quick response. Actually we were using NamedParameterJdbcTemplate#query(String, SqlParameterSource, RowCallbackHandler)

  4. spring-projects-issues commented on Jan 9, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    How is SqlParameterSourceUtils#extractCaseInsensitiveParameterNames being reached there? It only seems to be called from Table/CallMetaDataContext which is only being used by AbstractJdbcInsert/Call.

  5. spring-projects-issues commented on Jan 9, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Philippe Marschall commented

    I confused two things. We have a custom NamedParameterJdbcTemplate subclass that uses Oracle extensions (OraclePreparedStatement#setObjectAtName) to directly bind parameters by name without having to parse and rewrite the query.

    We could contribute the implementation if that is of interest, it would need some cleanup (eg. we compile against Oracle classes which would be a no-go for Spring).

  6. spring-projects-issues commented on Jan 9, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Alright, my implementation here should be good to go then.

    As for the Oracle extension, you could consider submitting it to the Spring Data JDBC Extensions project which has plenty of Oracle extensions already (built against the Oracle JDBC driver API): https://github.com/spring-projects/spring-data-jdbc-ext/tree/master/spring-data-oracle

  7. spring-projects-issues commented on Jan 9, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Philippe Marschall commented

    Thank you, I wasn't aware of this.

  8. added
    in: data
    type: enhancement
    on Jan 11, 2019
  9. added this to the 5.0.3 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datatype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions