Bug 46932 - Alias given in select statement is not used as column header in response data for a JDBC request
Summary: Alias given in select statement is not used as column header in response data...
Status: RESOLVED FIXED
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 2.11
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-27 13:21 UTC by mark.aronszajn
Modified: 2014-05-25 20:35 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mark.aronszajn 2009-03-27 13:21:35 UTC
If you use an alias for an existing column name in a select statement used within a JDBCSampler request, the original column name is returned with the response data rather than the alias proposed. Any DB client will return the given alias as a column header and so should JMeter's JDBCSampler.

For example, if the column is 'expected_arrival_time' and the query is

select residential_street_address as address from residence where id = 3;

the response data element will be

<responseData class="java.lang.String">residential_street_address
222 W. 58th Avenue</responseData>

One exceptional case: if the alias is given for a derived column in a view, the alias is used as expected.

This derives from behavior of methods in ResultSetMetaData. In the Sampler code, the ResultSetMetaData getColumnName(int) method is used to retrieve a column header rather than getColumnLabel(int). I believe the latter always gives the appropriate result.
Comment 1 mark.aronszajn 2009-03-27 13:24:06 UTC
(In reply to comment #0)
> If you use an alias for an existing column name in a select statement used
> within a JDBCSampler request, the original column name is returned with the
> response data rather than the alias proposed. Any DB client will return the
> given alias as a column header and so should JMeter's JDBCSampler.
> 
> For example, if the column is 'expected_arrival_time' and the query is
> 
> select residential_street_address as address from residence where id = 3;
> 
> the response data element will be
> 
> <responseData class="java.lang.String">residential_street_address
> 222 W. 58th Avenue</responseData>
> 
> One exceptional case: if the alias is given for a derived column in a view, the
> alias is used as expected.
> 
> This derives from behavior of methods in ResultSetMetaData. In the Sampler
> code, the ResultSetMetaData getColumnName(int) method is used to retrieve a
> column header rather than getColumnLabel(int). I believe the latter always
> gives the appropriate result.

Of course, where I begin to give my example and say, "...if the column is 'expected_arrival_time' and...", I meant to put 'residential_street_address'.
Comment 2 Sebb 2009-04-03 02:32:32 UTC
This has been fixed in SVN as part of Bug 46522
Comment 3 ambrosetti.nicola 2014-04-05 19:13:21 UTC
This bug is still present. The issue is not due to a bug in any JDBC driver, but rather in the JDBC Sampler. In particular if you look at the code in  src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java you see that the method getStringFromResultSet(ResultSet rs) the method ResultSetMetaData.getColumnName(i) is used (in two places) instead of getColumnLabel(), which correctly returns the alias name.

See also:
http://stackoverflow.com/questions/12709814/column-aliasing-in-select-statements-doesnt-work-with-squirrel-sql-firebird
and 
http://bugs.mysql.com/bug.php?id=43684
Comment 4 Philippe Mouawad 2014-05-25 20:35:17 UTC
Date: Sun May 25 20:34:37 2014
New Revision: 1597469

URL: http://svn.apache.org/r1597469
Log:
Bug 46932 - Alias given in select statement is not used as column header in response data for a JDBC request
Bugzilla Id: 46932

Modified:
    jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
    jmeter/trunk/xdocs/changes.xml
Comment 5 Philippe Mouawad 2014-05-25 20:35:41 UTC
@Nicola, Thanks for report and analysis