Search in sources :

Example 6 with BLangSelectExpression

use of org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectExpression in project ballerina by ballerina-lang.

the class SqlQueryBuilder method createSQLSelectExpressionClause.

private void createSQLSelectExpressionClause(BLangSelectClause select) {
    List<? extends SelectExpressionNode> selectExprList = select.getSelectExpressions();
    selectExprClause = new StringBuilder();
    selectExprClause.append("select ");
    if (selectExprList != null && !selectExprList.isEmpty()) {
        Iterator<? extends SelectExpressionNode> iterator = selectExprList.iterator();
        BLangSelectExpression selectExpression = (BLangSelectExpression) iterator.next();
        selectExpression.accept(this);
        selectExprClause.append(selectExpr);
        while (iterator.hasNext()) {
            selectExpression = (BLangSelectExpression) iterator.next();
            selectExprClause.append(", ");
            selectExpression.accept(this);
            selectExprClause.append(selectExpr);
        }
    } else if (select.isSelectAll()) {
        selectExprClause.append("* ");
    }
}
Also used : BLangSelectExpression(org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectExpression)

Example 7 with BLangSelectExpression

use of org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectExpression in project ballerina by ballerina-lang.

the class TypeChecker method visit.

@Override
public void visit(BLangSelectClause selectClause) {
    List<? extends SelectExpressionNode> selectExprList = selectClause.getSelectExpressions();
    selectExprList.forEach(selectExpr -> ((BLangSelectExpression) selectExpr).accept(this));
    BLangGroupBy groupBy = (BLangGroupBy) selectClause.getGroupBy();
    if (groupBy != null) {
        groupBy.accept(this);
    }
    BLangHaving having = (BLangHaving) selectClause.getHaving();
    if (having != null) {
        having.accept(this);
    }
}
Also used : BLangGroupBy(org.wso2.ballerinalang.compiler.tree.clauses.BLangGroupBy) BLangHaving(org.wso2.ballerinalang.compiler.tree.clauses.BLangHaving)

Example 8 with BLangSelectExpression

use of org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectExpression in project ballerina by ballerina-lang.

the class SqlQueryBuilder method visit.

@Override
public void visit(BLangSelectExpression selectExpression) {
    BLangExpression expr = (BLangExpression) selectExpression.getExpression();
    selectExpr = new StringBuilder();
    addParametrizedSQL(expr, selectExpr, selectExprParams);
    String identifier = selectExpression.getIdentifier();
    if (identifier != null) {
        selectExpr.append(" as ").append(identifier);
    }
}
Also used : BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Aggregations

BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 BLangSelectExpression (org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectExpression)3 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)2 BLangGroupBy (org.wso2.ballerinalang.compiler.tree.clauses.BLangGroupBy)2 BLangHaving (org.wso2.ballerinalang.compiler.tree.clauses.BLangHaving)2 GroupByNode (org.ballerinalang.model.tree.clauses.GroupByNode)1 HavingNode (org.ballerinalang.model.tree.clauses.HavingNode)1 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)1