use of com.developmentontheedge.sql.model.AstFirstDayOf 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.AstFirstDayOf in project be5 by DevelopmentOnTheEdge.
the class DB2Transformer method transformDateAdd.
@Override
protected void transformDateAdd(AstFunNode node) {
Function opPlus = DefaultParserContext.FUNC_PLUS;
Function opTimes = DefaultParserContext.FUNC_TIMES;
SimpleNode date = node.child(0);
SimpleNode number = node.child(1);
String name = node.getFunction().getName();
String type = name.equalsIgnoreCase("add_months") ? "MONTHS" : name.equalsIgnoreCase("add_days") ? "DAYS" : "MICROSECONDS";
if (type.equals("MICROSECONDS"))
number = new AstParenthesis(opTimes.node(number, AstNumericConstant.of(1000)));
node.replaceWith(new AstParenthesis(opPlus.node(date, new AstFirstDayOf(number, type))));
}
Aggregations