Search in sources :

Example 1 with AstSpecialConstant

use of com.developmentontheedge.sql.model.AstSpecialConstant in project be5 by DevelopmentOnTheEdge.

the class MySqlTransformer method transformDecode.

@Override
protected void transformDecode(AstFunNode node) {
    AstCase astCase = new AstCase();
    for (int i = 1; i < node.jjtGetNumChildren() - 1; i++) {
        SimpleNode cond;
        if (node.child(i) instanceof AstSpecialConstant) {
            cond = new AstNullPredicate(0);
            cond.addChild(node.child(0));
        } else {
            cond = DefaultParserContext.FUNC_EQ.node(node.child(0), node.child(i));
        }
        astCase.addChild(new AstWhen(cond, node.child(++i)));
        if (i == node.jjtGetNumChildren() - 2) {
            astCase.addChild(new AstCaseElse(node.child(++i)));
        }
    }
    node.replaceWith(astCase);
}
Also used : AstCaseElse(com.developmentontheedge.sql.model.AstCaseElse) AstWhen(com.developmentontheedge.sql.model.AstWhen) AstCase(com.developmentontheedge.sql.model.AstCase) AstNullPredicate(com.developmentontheedge.sql.model.AstNullPredicate) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstSpecialConstant(com.developmentontheedge.sql.model.AstSpecialConstant)

Example 2 with AstSpecialConstant

use of com.developmentontheedge.sql.model.AstSpecialConstant in project be5 by DevelopmentOnTheEdge.

the class PostgreSqlTransformer method transformDecode.

@Override
protected void transformDecode(AstFunNode node) {
    AstCase astCase = new AstCase();
    for (int i = 1; i < node.jjtGetNumChildren() - 1; i++) {
        SimpleNode cond;
        if (node.child(i) instanceof AstSpecialConstant) {
            cond = new AstNullPredicate(0);
            cond.addChild(node.child(0));
        } else {
            cond = DefaultParserContext.FUNC_EQ.node(node.child(0), node.child(i));
        }
        astCase.addChild(new AstWhen(cond, node.child(++i)));
        if (i == node.jjtGetNumChildren() - 2) {
            astCase.addChild(new AstCaseElse(node.child(++i)));
        }
    }
    node.replaceWith(astCase);
}
Also used : AstCaseElse(com.developmentontheedge.sql.model.AstCaseElse) AstWhen(com.developmentontheedge.sql.model.AstWhen) AstCase(com.developmentontheedge.sql.model.AstCase) AstNullPredicate(com.developmentontheedge.sql.model.AstNullPredicate) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstSpecialConstant(com.developmentontheedge.sql.model.AstSpecialConstant)

Example 3 with AstSpecialConstant

use of com.developmentontheedge.sql.model.AstSpecialConstant in project be5 by DevelopmentOnTheEdge.

the class SqlServerTransformer method transformDecode.

@Override
protected void transformDecode(AstFunNode node) {
    AstCase astCase = new AstCase();
    for (int i = 1; i < node.jjtGetNumChildren() - 1; i++) {
        SimpleNode cond;
        if (node.child(i) instanceof AstSpecialConstant) {
            cond = new AstNullPredicate(0);
            cond.addChild(node.child(0));
        } else {
            cond = DefaultParserContext.FUNC_EQ.node(node.child(0), node.child(i));
        }
        astCase.addChild(new AstWhen(cond, node.child(++i)));
        if (i == node.jjtGetNumChildren() - 2) {
            astCase.addChild(new AstCaseElse(node.child(++i)));
        }
    }
    node.replaceWith(astCase);
}
Also used : AstCaseElse(com.developmentontheedge.sql.model.AstCaseElse) AstWhen(com.developmentontheedge.sql.model.AstWhen) AstCase(com.developmentontheedge.sql.model.AstCase) AstNullPredicate(com.developmentontheedge.sql.model.AstNullPredicate) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstSpecialConstant(com.developmentontheedge.sql.model.AstSpecialConstant)

Aggregations

AstCase (com.developmentontheedge.sql.model.AstCase)3 AstCaseElse (com.developmentontheedge.sql.model.AstCaseElse)3 AstNullPredicate (com.developmentontheedge.sql.model.AstNullPredicate)3 AstSpecialConstant (com.developmentontheedge.sql.model.AstSpecialConstant)3 AstWhen (com.developmentontheedge.sql.model.AstWhen)3 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)3