use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method transformDateAdd.
@Override
protected void transformDateAdd(AstFunNode node) {
SimpleNode date = node.child(0);
SimpleNode number = node.child(1);
String name = node.getFunction().getName();
String type = name.equalsIgnoreCase("add_months") ? "MONTH" : name.equalsIgnoreCase("add_days") ? "DAY" : "MILLISECOND";
node.replaceWith(DATEADD.node(new AstIdentifierConstant(type), number, date));
}
use of com.developmentontheedge.sql.model.SimpleNode 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);
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method transformLastDay.
@Override
protected void transformLastDay(AstFunNode node) {
SimpleNode date = node.child(0);
transformLastDay(node, date);
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method transformLeastGreatest.
@Override
protected void transformLeastGreatest(AstFunNode node) {
String name = node.getFunction().getName();
AstIdentifierConstant v = new AstIdentifierConstant("V");
Function func;
if ("LEAST".equals(name))
func = parserContext.getFunction("min");
else
func = parserContext.getFunction("max");
AstValues values = new AstValues(0);
for (SimpleNode child : node.children()) values.addChild(new AstParenthesis(child));
AstTableRef tableRef = new AstTableRef(new AstParenthesis(values), new AstIdentifierConstant(name), new AstColumnList(v));
node.replaceWith(new AstParenthesis(new AstSelect(new AstSelectList(func.node(v)), new AstFrom(tableRef))));
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method transformLpad.
@Override
protected void transformLpad(AstFunNode node) {
Function opConcat = DefaultParserContext.FUNC_PLUS;
SimpleNode str = node.child(0);
SimpleNode fill = node.child(2);
SimpleNode size = node.child(1);
SimpleNode rsize = size.clone();
node.replaceWith(RIGHT.node(opConcat.node(REPLICATE.node(fill, size), str), rsize));
}
Aggregations