You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by kuro <96...@gmail.com> on 2013/12/05 09:40:23 UTC
[bug:sql] SQL Component cannot change SQL_ROW_COUNT header value
Hi
If SQL_ROW_COUNT header is already set,
SQL Component cannot change SQL_ROW_COUNT header value.
from("direct:test")
.setHeader(SqlConstants.SQL_ROW_COUNT).constant(100000)
.to("sql:SELECT * FROM user WHERE FALSE")
.filter(header(SqlConstants.SQL_ROW_COUNT).isEqualTo(100000))
.to("log:NG");
--
View this message in context: http://camel.465427.n5.nabble.com/bug-sql-SQL-Component-cannot-change-SQL-ROW-COUNT-header-value-tp5744350.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: [bug:sql] SQL Component cannot change SQL_ROW_COUNT header value
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Yep its a little bug
https://issues.apache.org/jira/browse/CAMEL-7058
On Thu, Dec 5, 2013 at 12:05 PM, Dharmendra Patel
<dh...@gmail.com> wrote:
> Hi There,
> I think it is a bug.
> in org.apache.camel.component.sql.SqlProducer class code highlighted in
> red(line no 120) could be shifted to line no 92(highlighted in green).
>
> else {
> boolean isResultSet = ps.execute();
> if (isResultSet) {
> * // preserve headers*
> *
> exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());*
> ResultSet rs = ps.getResultSet();
> SqlOutputType outputType =
> getEndpoint().getOutputType();
> log.trace("Got result list from query: {},
> outputType={}", rs, outputType);
> if (outputType == SqlOutputType.SelectList) {
> List<Map<String, Object>> data =
> getEndpoint().queryForList(ps.getResultSet());
> // for noop=true we still want to enrich with
> the row count header
> if (getEndpoint().isNoop()) {
>
> exchange.getOut().setBody(exchange.getIn().getBody());
> } else {
> exchange.getOut().setBody(data);
> }
>
> exchange.getOut().setHeader(SqlConstants.SQL_ROW_COUNT, data.size());
> } else if (outputType == SqlOutputType.SelectOne) {
> Object data =
> getEndpoint().queryForObject(ps.getResultSet());
> if (data != null) {
> // for noop=true we still want to enrich
> with the row count header
> if (getEndpoint().isNoop()) {
>
> exchange.getOut().setBody(exchange.getIn().getBody());
> } else {
> exchange.getOut().setBody(data);
> }
>
> exchange.getOut().setHeader(SqlConstants.SQL_ROW_COUNT, 1);
> }
> } else {
> throw new IllegalArgumentException("Invalid
> outputType=" + outputType);
> }
>
> * // preserve headers*
> *
> exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());*
> } else {
>
> exchange.getIn().setHeader(SqlConstants.SQL_UPDATE_COUNT,
> ps.getUpdateCount());
> }
> }
>
>
> On Thu, Dec 5, 2013 at 2:10 PM, kuro <96...@gmail.com> wrote:
>
>> Hi
>>
>> If SQL_ROW_COUNT header is already set,
>> SQL Component cannot change SQL_ROW_COUNT header value.
>>
>> from("direct:test")
>> .setHeader(SqlConstants.SQL_ROW_COUNT).constant(100000)
>> .to("sql:SELECT * FROM user WHERE FALSE")
>> .filter(header(SqlConstants.SQL_ROW_COUNT).isEqualTo(100000))
>> .to("log:NG");
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/bug-sql-SQL-Component-cannot-change-SQL-ROW-COUNT-header-value-tp5744350.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: [bug:sql] SQL Component cannot change SQL_ROW_COUNT header value
Posted by Dharmendra Patel <dh...@gmail.com>.
Hi There,
I think it is a bug.
in org.apache.camel.component.sql.SqlProducer class code highlighted in
red(line no 120) could be shifted to line no 92(highlighted in green).
else {
boolean isResultSet = ps.execute();
if (isResultSet) {
* // preserve headers*
*
exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());*
ResultSet rs = ps.getResultSet();
SqlOutputType outputType =
getEndpoint().getOutputType();
log.trace("Got result list from query: {},
outputType={}", rs, outputType);
if (outputType == SqlOutputType.SelectList) {
List<Map<String, Object>> data =
getEndpoint().queryForList(ps.getResultSet());
// for noop=true we still want to enrich with
the row count header
if (getEndpoint().isNoop()) {
exchange.getOut().setBody(exchange.getIn().getBody());
} else {
exchange.getOut().setBody(data);
}
exchange.getOut().setHeader(SqlConstants.SQL_ROW_COUNT, data.size());
} else if (outputType == SqlOutputType.SelectOne) {
Object data =
getEndpoint().queryForObject(ps.getResultSet());
if (data != null) {
// for noop=true we still want to enrich
with the row count header
if (getEndpoint().isNoop()) {
exchange.getOut().setBody(exchange.getIn().getBody());
} else {
exchange.getOut().setBody(data);
}
exchange.getOut().setHeader(SqlConstants.SQL_ROW_COUNT, 1);
}
} else {
throw new IllegalArgumentException("Invalid
outputType=" + outputType);
}
* // preserve headers*
*
exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());*
} else {
exchange.getIn().setHeader(SqlConstants.SQL_UPDATE_COUNT,
ps.getUpdateCount());
}
}
On Thu, Dec 5, 2013 at 2:10 PM, kuro <96...@gmail.com> wrote:
> Hi
>
> If SQL_ROW_COUNT header is already set,
> SQL Component cannot change SQL_ROW_COUNT header value.
>
> from("direct:test")
> .setHeader(SqlConstants.SQL_ROW_COUNT).constant(100000)
> .to("sql:SELECT * FROM user WHERE FALSE")
> .filter(header(SqlConstants.SQL_ROW_COUNT).isEqualTo(100000))
> .to("log:NG");
>
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/bug-sql-SQL-Component-cannot-change-SQL-ROW-COUNT-header-value-tp5744350.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>