Search in sources :

Example 1 with AstDateAdd

use of com.developmentontheedge.sql.model.AstDateAdd 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));
}
Also used : Function(com.developmentontheedge.sql.model.Function) PredefinedFunction(com.developmentontheedge.sql.model.PredefinedFunction) AstDateAdd(com.developmentontheedge.sql.model.AstDateAdd) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) AstInterval(com.developmentontheedge.sql.model.AstInterval) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Aggregations

AstDateAdd (com.developmentontheedge.sql.model.AstDateAdd)1 AstInterval (com.developmentontheedge.sql.model.AstInterval)1 AstParenthesis (com.developmentontheedge.sql.model.AstParenthesis)1 Function (com.developmentontheedge.sql.model.Function)1 PredefinedFunction (com.developmentontheedge.sql.model.PredefinedFunction)1 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)1