use of com.developmentontheedge.sql.model.AstWhen in project be5 by DevelopmentOnTheEdge.
the class MySqlTransformer 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.AstWhen in project be5 by DevelopmentOnTheEdge.
the class PostgreSqlTransformer 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.AstWhen 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.AstWhen in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method getDateTimeDiff.
@Override
protected SimpleNode getDateTimeDiff(SimpleNode startDate, SimpleNode endDate, String format) {
int dp;
switch(format) {
case "YEAR":
format = "yy";
dp = 5;
break;
case "MONTH":
format = "mm";
dp = 2;
break;
case "DAY":
return DATEDIFF.node(new AstIdentifierConstant("dd"), startDate, endDate);
case "HOUR":
format = "hh";
dp = 9;
break;
case "MINUTE":
format = "mi";
dp = 6;
break;
case "SECOND":
format = "ss";
dp = 3;
break;
default:
throw new IllegalStateException("Unsupported value for datepart in TIMESTAMPDIFF: " + format);
}
AstFunNode dateDiff = DATEDIFF.node(new AstIdentifierConstant(format), startDate, endDate);
AstFunNode cond = parserContext.getFunction("<=").node(getDatePart(startDate, dp, format), getDatePart(endDate, dp, format));
return new AstCase(new AstWhen(cond, dateDiff), new AstCaseElse(DefaultParserContext.FUNC_MINUS.node(dateDiff, AstNumericConstant.of(1))));
}
Aggregations