Search in sources :

Example 1 with QueryFunction

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;
}
Also used : QueryAggregate(com.servoy.j2db.query.QueryAggregate) QueryColumn(com.servoy.j2db.query.QueryColumn) QueryFunction(com.servoy.j2db.query.QueryFunction) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 2 with QueryFunction

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);
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider) SetCondition(com.servoy.j2db.query.SetCondition) QueryColumnValue(com.servoy.j2db.query.QueryColumnValue) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) QueryFunction(com.servoy.j2db.query.QueryFunction) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

Example 3 with QueryFunction

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);
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) DisplayString(com.servoy.j2db.dataprocessing.CustomValueList.DisplayString) QuerySelect(com.servoy.j2db.query.QuerySelect) QueryFunction(com.servoy.j2db.query.QueryFunction) CompareCondition(com.servoy.j2db.query.CompareCondition) RemoteException(java.rmi.RemoteException)

Aggregations

QueryFunction (com.servoy.j2db.query.QueryFunction)3 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 IQuerySelectValue (com.servoy.j2db.query.IQuerySelectValue)2 QueryColumn (com.servoy.j2db.query.QueryColumn)2 BaseQueryColumn (com.servoy.base.query.BaseQueryColumn)1 DisplayString (com.servoy.j2db.dataprocessing.CustomValueList.DisplayString)1 Column (com.servoy.j2db.persistence.Column)1 IColumn (com.servoy.j2db.persistence.IColumn)1 IDataProvider (com.servoy.j2db.persistence.IDataProvider)1 CompareCondition (com.servoy.j2db.query.CompareCondition)1 Placeholder (com.servoy.j2db.query.Placeholder)1 QueryAggregate (com.servoy.j2db.query.QueryAggregate)1 QueryColumnValue (com.servoy.j2db.query.QueryColumnValue)1 QuerySelect (com.servoy.j2db.query.QuerySelect)1 SetCondition (com.servoy.j2db.query.SetCondition)1 RemoteException (java.rmi.RemoteException)1 JSFunction (org.mozilla.javascript.annotations.JSFunction)1