use of com.developmentontheedge.sql.model.SimpleNode 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);
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class OracleTransformer method transformCoalesce.
@Override
protected void transformCoalesce(AstFunNode node) {
if (node.jjtGetNumChildren() < 2)
throw new IllegalStateException("COALESCE node must contain at least two arguments: " + node.format());
int num = node.jjtGetNumChildren() - 1;
SimpleNode lastNode = node.removeChild(num);
while (--num >= 1) {
lastNode = NVL.node(node.removeChild(num), lastNode);
}
node.addChild(lastNode);
node.setFunction(NVL);
}
use of com.developmentontheedge.sql.model.SimpleNode 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);
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class ContextApplier method applySessionTag.
private void applySessionTag(AstBeSessionTag child) {
String name = child.getName();
Object value = context.getSessionVariable(name);
if (value == null) {
if (child.getDefault() != null) {
value = SqlTypeUtils.parseValue(child.getDefault(), child.getType());
} else {
value = "";
}
}
SimpleNode replacement;
// TODO: support refColumn; smart quoting - in server module
if (child.jjtGetParent() instanceof AstStringConstant) {
replacement = new AstStringPart(value.toString());
} else {
if (SqlTypeUtils.isNumber(value.getClass())) {
replacement = AstNumericConstant.of((Number) value);
} else {
replacement = new AstStringConstant(value.toString());
}
}
child.replaceWith(replacement);
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class ContextApplier method setIfResult.
private int setIfResult(SimpleNode newTree, int i, SimpleNode condNode, boolean correct) {
SimpleNode child;
for (int j = condNode.jjtGetNumChildren() - 1; j >= 0; j--) {
child = condNode.child(j);
if (child instanceof AstBeThen && correct || child instanceof AstBeElse && !correct) {
if (child.jjtGetNumChildren() != 0)
setChildren(newTree, i, child);
else {
newTree.removeChild(condNode);
i--;
}
break;
} else if (child instanceof AstBeThen && !correct) {
newTree.removeChild(condNode);
i--;
}
}
return i;
}
Aggregations