use of com.developmentontheedge.sql.model.SimpleNode 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.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method transformDateFormat.
@Override
protected void transformDateFormat(AstFunNode node, DateFormat df) {
Number length, codePage;
switch(df) {
case FORMAT_DATE:
length = 10;
codePage = 120;
break;
case FORMAT_DATETIME:
length = 19;
codePage = 120;
break;
case FORMAT_DATE_RUS:
length = 10;
codePage = 104;
break;
case FORMAT_DATE_RUS_SHORT:
length = 8;
codePage = 4;
break;
case FORMAT_MONTHYEAR:
length = 4;
codePage = 120;
break;
case FORMAT_FMDAYMONTH:
case FORMAT_DAYMONTH:
length = 5;
codePage = 4;
break;
case FORMAT_HOURMINUTE:
length = 5;
codePage = 114;
break;
case FORMAT_YYYYMMDD:
length = 8;
codePage = 112;
break;
case FORMAT_YYYYMM:
length = 6;
codePage = 112;
break;
case FORMAT_DAY_OF_WEEK:
node.replaceWith(DATEPART.node(new AstIdentifierConstant("dw"), node.child(0)));
return;
default:
SimpleNode rtrim = RTRIM.node(parserContext.getFunction(df.name()).node(node.child(0)));
SimpleNode padded = DefaultParserContext.FUNC_PLUS.node(new AstStringConstant("0"), rtrim);
node.replaceWith(RIGHT.node(padded, AstNumericConstant.of(df == DateFormat.YEAR ? 4 : 2)));
return;
}
SimpleNode replacement = CONVERT.node(VARCHAR.node(AstNumericConstant.of(length)), node.child(0), AstNumericConstant.of(codePage));
if (DateFormat.FORMAT_MONTHYEAR.equals(df))
replacement = DefaultParserContext.FUNC_PLUS.node(DATENAME.node(new AstIdentifierConstant("month"), node.child(0)), new AstStringConstant(" "), replacement);
node.replaceWith(replacement);
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class MacroExpander method transformMacroFunction.
private void transformMacroFunction(AstFunNode node) {
BeMacroFunction function = (BeMacroFunction) node.getFunction();
SimpleNode replacement = function.getReplacement(node);
expandMacros(replacement);
node.replaceWith(replacement);
}
use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class MySqlTransformer method transformConcat.
@Override
protected void transformConcat(AstFunNode node) {
if (isConcat(node))
return;
node.setFunction(parserContext.getFunction("concat"));
List<SimpleNode> flatChildren = node.children().flatMap(child -> isConcat(child) ? child.children() : Stream.of(child)).toList();
node.removeChildren();
flatChildren.forEach(node::addChild);
SimpleNode parent = node.jjtGetParent();
if (parent instanceof AstParenthesis)
parent.replaceWith(node);
}
use of com.developmentontheedge.sql.model.SimpleNode 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