Claus Ibsen created CAMEL-26067:
-----------------------------------

             Summary: camel-jdbc - useHeadersAsParameters should not bind every 
message header by position to plain ? placeholders
                 Key: CAMEL-26067
                 URL: https://issues.apache.org/jira/browse/CAMEL-26067
             Project: Camel
          Issue Type: Improvement
          Components: camel-jdbc
            Reporter: Claus Ibsen
             Fix For: 4.24.0


With {{useHeadersAsParameters=true}} the jdbc producer (and spring-jdbc) runs 
the SQL in the body as a prepared statement and takes the parameter values from 
the message headers. The option is documented for named parameters 
({{:?name}}), which are looked up by name.

When the query has only plain {{?}} placeholders, 
{{DefaultJdbcPrepareStatementStrategy.createPopulateIterator}} (main 
faa015319ee7, lines 120-123) binds the values of all the message headers by 
position instead (or of the {{CamelJdbcParameters}} map when that header is 
set), until the statement has as many values as it needs. Which value goes to 
which {{?}} then depends on which headers the message has and in what order, 
including the headers set by the consumer and Camel's own headers, not on the 
query. That order also changed in 4.21 (CAMEL-23691): the header map used to 
sort the names alphabetically and now keeps them in the order they were added, 
so the same route binds other values after an upgrade from 4.18 when the 
message has more than one header.

This dates from CAMEL-6157; its only test 
({{JdbcParameterizedQueryTest.testParameterizedQueryNoNames}}) uses a single 
header.

*Proposal*:
* with plain {{?}} placeholders, take the values only from the 
{{CamelJdbcParameters}} header (a List, or a Map in the order of its entries), 
and fail with a clear message when it is not set;
* named parameters work as today;
* say it in the docs and in the 4.24 upgrade guide.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to