use of org.hsqldb_voltpatches.ColumnBase in project voltdb by VoltDB.
the class Result method newSingleColumnResult.
public static Result newSingleColumnResult(String colName, Type type) {
Result result = newResult(ResultConstants.DATA);
result.metaData = ResultMetaData.newResultMetaData(1);
result.metaData.columns[0] = new ColumnBase(null, null, null, colName);
result.metaData.columns[0].setType(type);
result.metaData.prepareData();
//
result.navigator = new RowSetNavigatorClient(8);
return result;
}
use of org.hsqldb_voltpatches.ColumnBase in project voltdb by VoltDB.
the class JDBCResultSet method findColumn.
//----------------------------------------------------------------
/**
* <!-- start generic documentation -->
* Maps the given <code>ResultSet</code> column label to its
* <code>ResultSet</code> column index.
* <!-- end generic documentation -->
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HSQLDB-Specific Information:</h3> <p>
*
* Starting with 1.9.x, HSQLDB does an exhaustive search, backed by
* a cache lookup (to improve performance for subsequent invocations with
* a given input). <p>
*
* This is in response to an observation posted here: <p>
*
* http://sourceforge.net/forum/forum.php?thread_id=1388727&forum_id=73674<p>
*
* Upon careful investigation of the JDBC specification and the behaviour
* of existing JDBC drivers, there is actually nothing preventing the
* findColumn method from doing an exhaustive search, as long as it conforms
* to the following rules (which describe the new implementation): <p>
*
* <ol>
* <li> the entire search is case insensitive
* <li> each search iteration occurs from leftmost to rightmost column,
* returning the first match encountered
* <li> the first pass matches only bare column labels
* <li> the second pass matches only simple column names
* <li> further passes conform to the identifier qualification
* and identifier quoting rules of the engine
* </ol>
*
* In this implementation, the SQL tokenizer is not employed, both because
* it does not yet correctly handle greater than two part qualification
* and also because is is not immediately considered important to do a
* truly exhaustive search, handling the full range of possibly mixed quoted
* and unquoted identifier components. <p>
*
* Instead: <p>
* <ul>
* <li> a third pass matches simple table-dot-column qualified names
* <li> a fourth pass matches simple schema-dot-table-dot-column qualified column names
* </ul>
* </div>
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column index of the given column name
* @exception SQLException if the <code>ResultSet</code> object
* does not contain a column labeled <code>columnLabel</code>, a database access error occurs
* or this method is called on a closed result set
*/
public int findColumn(final String columnLabel) throws SQLException {
checkClosed();
if (columnLabel == null) {
throw Util.nullArgument();
}
int columnIndex;
// faster lookup for subsequent access
if (columnMap != null) {
columnIndex = columnMap.get(columnLabel, -1);
if (columnIndex != -1) {
return columnIndex;
}
}
final String[] colLabels = resultMetaData.columnLabels;
columnIndex = -1;
// column labels first, to preference column aliases
for (int i = 0; i < columnCount; i++) {
if (columnLabel.equalsIgnoreCase(colLabels[i])) {
columnIndex = i;
break;
}
}
final ColumnBase[] columns = resultMetaData.columns;
// quoted column idents that *may* contain "."
if (columnIndex < 0) {
for (int i = 0; i < columnCount; i++) {
if (columnLabel.equalsIgnoreCase(columns[i].getNameString())) {
columnIndex = i;
break;
}
}
}
// (we don't yet bother with catalog qualification)
if (columnIndex < 0) {
int position = columnLabel.indexOf('.');
if (position < 0) {
throw Util.sqlException(ErrorCode.JDBC_COLUMN_NOT_FOUND, columnLabel);
}
for (int i = 0; i < columnCount; i++) {
final String tabName = columns[i].getTableNameString();
if (tabName == null || tabName.length() == 0) {
continue;
}
final String colName = columns[i].getNameString();
if (columnLabel.equalsIgnoreCase(tabName + '.' + colName)) {
columnIndex = i;
break;
}
final String schemName = columns[i].getSchemaNameString();
if (schemName == null || schemName.length() == 0) {
continue;
}
String match = new StringBuffer(schemName).append('.').append(tabName).append('.').append(colName).toString();
if (columnLabel.equalsIgnoreCase(match)) {
columnIndex = i;
break;
}
}
}
if (columnIndex < 0) {
throw Util.sqlException(ErrorCode.JDBC_COLUMN_NOT_FOUND, columnLabel);
}
columnIndex++;
if (columnMap == null) {
columnMap = new IntValueHashMap();
}
columnMap.put(columnLabel, columnIndex);
return columnIndex;
}
Aggregations