Quantcast
Viewing all articles
Browse latest Browse all 3131

Bug in the HANA JDBC Driver when working with column name aliases

Hi guys,

 

i recenty stumbled upon a bug when working with the hana jdbc driver. When retrieving the column names of a select statement via resultSet.getMetaData().getColumname(i) (where i is the index of the column) one won't receive the alias that might be assigned to this particular column. Instead one would receive the original column name, which is wrong. I wrote a small test case to reproduce this issue and hope u guys can help me with that. Maybe its already fixed in a newer version Image may be NSFW.
Clik here to view.

 

Further Details:

Implementation-Title: SAP In-Memory Database JDBC Driver

Implementation-Version: 1.00.56 Build 0377318-1510

 

Test case (will fail):

package myPackage;

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

import junit.framework.Assert;

 

import org.junit.Test;

 

/**

* Reproduces a jdbc bug in the hana jdbc driver. One can't resolve aliases as column names via meta data access.

*

* @date 30.07.2013

* @author TErnst

*/

public class GetAliasForColumnFromMetaDataTest {

 

    @Test

    public void getAlias() throws SQLException {

        try {

            Class.forName("com.sap.db.jdbc.Driver");

        } catch (ClassNotFoundException e) {

            throw new RuntimeException(e);

        }

 

       Connection connection = DriverManager.getConnection("jdbcUrl", "user", "password);

       Statement statement = connection.createStatement();

 

       statement.execute("create table TEST (col integer)");

 

       ResultSet resultSet = connection.createStatement().executeQuery("select col as alias from \"SYSTEM\".\"TEST\"");

       String aliasName = resultSet.getMetaData().getColumnName(1);

 

       connection.close();

 

       Assert.assertEquals("alias", aliasName);

    }

 

}

 

 

Kind regards

Thomas Ernst


Viewing all articles
Browse latest Browse all 3131

Trending Articles