I am trying to use the SQLQueryParser to parse a query statement and want to gather the result columns and their data type.
Currently I can successfully get the column name however the data type is not populated. I am not sure how I can pass the connection profile. I tried extracting the Database object from IConnectionProfile and passing it to StatementHelper but to no avail.
This is what I am trying right now:
Database db = getDatabaseForProfile(connection);
StatementHelper helper = new StatementHelper(db);
SQLQueryParserManager parserManager = SQLQueryParserManagerProvider.getInstance().getParserManager(db.getVendor(), db.getVersion());
QuerySelectStatement result = null;
try {
result = (QuerySelectStatement) parserManager.parseQuery(statement).getQueryStatement();
} catch (SQLParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLParserInternalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List columnList = helper.getEffectiveResultColumns(result);
Iterator<ValueExpressionColumn> columnIterator = columnList.iterator();
while(columnIterator.hasNext()){
ValueExpressionColumn column = columnIterator.next();
System.out.println("Column name is "+column.getName());
System.out.println("Column datatype is "+column.getDataType());
}
Any help is appreciated!
-Aditya