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

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

Closed
spring-issuemaster opened this issue Jan 9, 2018 · 7 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jan 9, 2018

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:

  • #20887 NamedParameterJdbcTemplate fails on PostgreSQL array
  • #20763 SqlParameterSourceUtils.createBatch with Collection support
  • #20759 Expose parameter names from ParsedSql
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 9, 2018

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.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 9, 2018

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.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 9, 2018

Philippe Marschall commented

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 9, 2018

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.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 9, 2018

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).

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 9, 2018

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 9, 2018

Philippe Marschall commented

Thank you, I wasn't aware of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.