use of org.jkiss.dbeaver.model.exec.DBCResultSet in project dbeaver by dbeaver.
the class JDBCTableColumn method getValueEnumeration.
@NotNull
@Override
public List<DBDLabelValuePair> getValueEnumeration(@NotNull DBCSession session, @Nullable Object valuePattern, int maxResults, boolean formatValues) throws DBException {
DBDValueHandler valueHandler = DBUtils.findValueHandler(session, this);
StringBuilder query = new StringBuilder();
query.append("SELECT ").append(DBUtils.getQuotedIdentifier(this)).append(", count(*)");
// Do not use description columns because they duplicate distinct value
// String descColumns = DBVUtils.getDictionaryDescriptionColumns(session.getProgressMonitor(), this);
// if (descColumns != null) {
// query.append(", ").append(descColumns);
// }
query.append("\nFROM ").append(DBUtils.getObjectFullName(getTable(), DBPEvaluationContext.DML));
if (valuePattern instanceof String) {
query.append("\nWHERE ").append(DBUtils.getQuotedIdentifier(this));
if (getDataKind() == DBPDataKind.STRING) {
query.append(" LIKE ?");
} else {
query.append(" = ?");
}
}
query.append("\nGROUP BY ").append(DBUtils.getQuotedIdentifier(this));
try (DBCStatement dbStat = session.prepareStatement(DBCStatementType.QUERY, query.toString(), false, false, false)) {
if (valuePattern instanceof String) {
if (getDataKind() == DBPDataKind.STRING) {
valueHandler.bindValueObject(session, dbStat, this, 0, "%" + valuePattern + "%");
} else {
valueHandler.bindValueObject(session, dbStat, this, 0, valuePattern);
}
}
dbStat.setLimit(0, maxResults);
if (dbStat.executeStatement()) {
try (DBCResultSet dbResult = dbStat.openResultSet()) {
return DBVUtils.readDictionaryRows(session, this, valueHandler, dbResult, formatValues);
}
} else {
return Collections.emptyList();
}
}
}
Aggregations