use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class DB2Transformer method transformDateTrunc.
@Override
protected void transformDateTrunc(AstFunNode node) {
Function opConcat = DefaultParserContext.FUNC_MINUS;
SimpleNode date = node.child(1);
String field = ((AstStringConstant) node.child(0)).getValue();
AstFirstDayOf month = new AstFirstDayOf(new AstParenthesis(opConcat.node(DAY.node(date), AstNumericConstant.of(1))), "DAYS");
if (field.equalsIgnoreCase("'MONTH'"))
node.replaceWith(opConcat.node(date, month));
else {
AstFirstDayOf year = new AstFirstDayOf(new AstParenthesis(opConcat.node(MONTH.node(date), AstNumericConstant.of(1))), "MONTHS");
node.replaceWith(opConcat.node(date, opConcat.node(year, month)));
}
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class GenericDbmsTransformer method transformDateTimeDiff.
protected void transformDateTimeDiff(AstFunNode node, String format) {
SimpleNode startDate = node.child(node.jjtGetNumChildren() - 2);
SimpleNode endDate = node.child(node.jjtGetNumChildren() - 1);
node.replaceWith(getDateTimeDiff(startDate, endDate, format));
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class GenericDbmsTransformer method expandDbFunction.
private void expandDbFunction(AstFunNode node, Dbms dbms) {
SimpleNode replacement = ((DbSpecificFunction) node.getFunction()).getReplacement(node, dbms);
expandDbArguments(replacement, dbms);
node.replaceWith(replacement);
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class GenericDbmsTransformer method transformInterval.
private void transformInterval(AstInterval interval) {
SimpleNode mul = interval.jjtGetParent();
if (AstFunNode.isFunction("*").test(mul)) {
String type = interval.getLiteral();
String fn;
switch(type) {
case "1 MONTH":
fn = "ADD_MONTHS";
break;
case "1 DAYS":
case "1 DAY":
fn = "ADD_DAYS";
break;
case "1 MILLISECOND":
fn = "ADD_MILLIS";
break;
default:
throw new IllegalStateException("Unsupported interval format: " + interval.format());
}
SimpleNode content = mul.other(interval);
if (content instanceof AstParenthesis)
content = ((AstParenthesis) content).child(0);
SimpleNode add = mul.jjtGetParent();
if (!AstFunNode.isFunction("+").test(add))
throw new IllegalStateException("Interval grandparent is " + add + ", expected addition");
SimpleNode date = add.other(mul);
AstFunNode addFunction = parserContext.getFunction(fn).node(date, content);
date.pullUpPrefix();
SimpleNode toReplace = add;
if (toReplace.jjtGetParent() instanceof AstParenthesis)
toReplace = toReplace.jjtGetParent();
toReplace.replaceWith(addFunction);
transformDateAdd(addFunction);
}
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class MacroExpander method expandMacros.
public void expandMacros(SimpleNode node) {
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
SimpleNode child = node.child(i);
expandMacros(child);
if ((child instanceof AstFunNode) && ((AstFunNode) child).getFunction() instanceof BeMacroFunction) {
transformMacroFunction((AstFunNode) child);
}
}
}
Aggregations