use of com.servoy.j2db.query.QueryFunction in project servoy-client by Servoy.
the class QBResult method getColumns.
/**
* returns an array with all the columns that will be in the select of this query.
* can return empty array. Then the system will auto append the pk when this query is used.
* @sample
* var columns = query.result.getColumns();
*
* @return An array of QBColumn thats in the select of this query.
*/
@JSFunction
public QBColumn[] getColumns() {
ArrayList<IQuerySelectValue> columns = getParent().getQuery().getColumns();
QBColumn[] result = new QBColumn[columns == null ? 0 : columns.size()];
for (int i = 0; i < result.length; i++) {
IQuerySelectValue selectValue = columns.get(i);
if (selectValue instanceof QueryColumn) {
result[i] = new QBColumn(getRoot(), getParent(), selectValue);
} else if (selectValue instanceof QueryAggregate) {
result[i] = new QBAggregate(getRoot(), getParent(), selectValue, ((QueryAggregate) selectValue).getType(), ((QueryAggregate) selectValue).getQuantifier());
} else if (selectValue instanceof QueryFunction) {
result[i] = new QBFunction(getRoot(), getParent(), ((QueryFunction) selectValue).getFunction(), ((QueryFunction) selectValue).getArgs());
}
}
return result;
}
use of com.servoy.j2db.query.QueryFunction in project servoy-client by Servoy.
the class SQLGenerator method createRelatedCondition.
public static ISQLCondition createRelatedCondition(IServiceProvider app, Relation relation, QueryTable foreignTable) throws RepositoryException {
IDataProvider[] primary = relation.getPrimaryDataProviders(app.getFlattenedSolution());
Column[] foreign = relation.getForeignColumns(app.getFlattenedSolution());
int[] operators = relation.getOperators();
IQuerySelectValue[] keys = new IQuerySelectValue[primary.length];
int[] swapped = new int[primary.length];
for (int x = 0; x < primary.length; x++) {
// need all keys as columns on the left side......
int operator = RelationItem.swapOperator(operators[x]);
if (operator == -1) {
throw new RepositoryException("Cannot swap relation operator for relation " + relation.getName());
}
// column = ? construct
IQuerySelectValue key = foreign[x].queryColumn(foreignTable);
// When we have a text and non-text column we can cast the non-text column to string
int primaryType = primary[x].getDataProviderType();
int foreignType = mapToDefaultType(key.getColumn().getColumnType());
if (!"uuid".equalsIgnoreCase(key.getColumn().getNativeTypename()) && foreignType == IColumnTypes.TEXT && primaryType != IColumnTypes.TEXT && primaryType != 0) {
// key is text, value is non-text, cast the value to text when we supply it
operator |= IBaseSQLCondition.CAST_TO_MODIFIER;
} else if (primaryType == IColumnTypes.TEXT && foreignType != IColumnTypes.TEXT) {
// value is text, key is non-text, cast the key to text
key = new QueryFunction(cast, new IQuerySelectValue[] { key, new QueryColumnValue(IQueryConstants.TYPE_STRING, null, true) }, null);
}
keys[x] = key;
swapped[x] = operator;
}
return new SetCondition(swapped, keys, new Placeholder(createRelationKeyPlaceholderKey(foreignTable, relation.getName())), true);
}
use of com.servoy.j2db.query.QueryFunction in project servoy-client by Servoy.
the class LookupListModel method fillDBColumnValues.
/**
* @param txt
* @throws Exception
* @throws RepositoryException
* @throws RemoteException
*/
private void fillDBColumnValues(String dataProviderID, String txt) throws ServoyException {
QuerySelect sqlParts = AbstractBaseQuery.deepClone(creationSQLParts);
sqlParts.clearCondition(SQLGenerator.CONDITION_SEARCH);
if (// $NON-NLS-1$
!"".equals(txt)) {
sqlParts.setCondition(SQLGenerator.CONDITION_SEARCH, new CompareCondition(IBaseSQLCondition.LIKE_OPERATOR, new QueryFunction(QueryFunctionType.upper, DBValueList.getQuerySelectValue(table, sqlParts.getTable(), dataProviderID), dataProviderID), txt.toUpperCase() + '%'));
} else {
sqlParts.clearCondition(SQLGenerator.CONDITION_SEARCH);
}
try {
FoundSetManager foundSetManager = ((FoundSetManager) application.getFoundSetManager());
String transaction_id = foundSetManager.getTransactionID(table.getServerName());
ArrayList<TableFilter> tableFilterParams = foundSetManager.getTableFilterParams(table.getServerName(), sqlParts);
if (// apply name as filter on column valuelist_name in creationSQLParts
nameFilter != null) {
if (tableFilterParams == null) {
tableFilterParams = new ArrayList<TableFilter>();
}
tableFilterParams.add(nameFilter);
}
SQLStatement trackingInfo = null;
if (foundSetManager.getEditRecordList().hasAccess(table, IRepository.TRACKING_VIEWS)) {
trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, table.getServerName(), table.getName(), null, null);
trackingInfo.setTrackingData(sqlParts.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
}
IDataSet set = application.getDataServer().performQuery(application.getClientID(), table.getServerName(), transaction_id, sqlParts, null, tableFilterParams, !sqlParts.isUnique(), 0, 100, IDataServer.VALUELIST_QUERY, trackingInfo);
for (int i = 0; i < set.getRowCount(); i++) {
Object[] row = set.getRow(i);
if (// $NON-NLS-1$
row[0] != null && !"".equals(row[0])) {
alReal.add(row[0]);
}
}
hadMoreRows = set.hadMoreRows();
} catch (RemoteException e) {
throw new RepositoryException(e);
}
}
Aggregations