use of com.developmentontheedge.sql.model.Function 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.Function 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.Function 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));
}
use of com.developmentontheedge.sql.model.Function in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method transformLastDay.
protected void transformLastDay(SimpleNode node, SimpleNode date) {
Function opConcat = DefaultParserContext.FUNC_PLUS;
SimpleNode dateDiff = DATEDIFF.node(new AstIdentifierConstant("MONTH"), AstNumericConstant.of(0), date);
SimpleNode dateAdd = DATEADD.node(new AstIdentifierConstant("MONTH"), opConcat.node(dateDiff, AstNumericConstant.of(1)), AstNumericConstant.of(0));
SimpleNode expr = DATEADD.node(new AstIdentifierConstant("DAY"), AstNumericConstant.of(-1), dateAdd);
node.replaceWith(CONVERT.node(new AstIdentifierConstant("DATE"), expr, AstNumericConstant.of(104)));
}
use of com.developmentontheedge.sql.model.Function in project be5 by DevelopmentOnTheEdge.
the class MySqlTransformer method transformDateAdd.
@Override
protected void transformDateAdd(AstFunNode node) {
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") ? "MONTH" : name.equalsIgnoreCase("add_days") ? "DAY" : "MICROSECOND";
if (type.equals("MICROSECOND"))
number = new AstParenthesis(opTimes.node(number, AstNumericConstant.of(1000)));
node.replaceWith(new AstDateAdd(date, new AstInterval(number), type));
}
Aggregations