use of com.developmentontheedge.sql.model.AstStringConstant 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.AstStringConstant in project be5 by DevelopmentOnTheEdge.
the class MySqlTransformer method transformDateTrunc.
@Override
protected void transformDateTrunc(AstFunNode node) {
AstStringConstant child = (AstStringConstant) node.child(0);
String dateformat = child.getValue().equalsIgnoreCase("'MONTH'") ? "%Y-%m-01" : "%Y-01-01";
node.replaceWith(parserContext.getFunction("date_format").node(node.child(1), new AstStringConstant(dateformat)));
}
use of com.developmentontheedge.sql.model.AstStringConstant in project be5 by DevelopmentOnTheEdge.
the class ContextApplier method applySessionTag.
private void applySessionTag(AstBeSessionTag child) {
String name = child.getName();
Object value = context.getSessionVariable(name);
if (value == null) {
if (child.getDefault() != null) {
value = SqlTypeUtils.parseValue(child.getDefault(), child.getType());
} else {
value = "";
}
}
SimpleNode replacement;
// TODO: support refColumn; smart quoting - in server module
if (child.jjtGetParent() instanceof AstStringConstant) {
replacement = new AstStringPart(value.toString());
} else {
if (SqlTypeUtils.isNumber(value.getClass())) {
replacement = AstNumericConstant.of((Number) value);
} else {
replacement = new AstStringConstant(value.toString());
}
}
child.replaceWith(replacement);
}
use of com.developmentontheedge.sql.model.AstStringConstant in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method transformDateTrunc.
@Override
protected void transformDateTrunc(AstFunNode node) {
AstStringConstant child = (AstStringConstant) node.child(0);
String dateformat = child.getValueUnescaped();
AstIdentifierConstant datepart = new AstIdentifierConstant(dateformat);
AstNumericConstant date = AstNumericConstant.of(0);
node.replaceWith(DATEADD.node(datepart, DATEDIFF.node(datepart, date, node.child(1)), date));
}
use of com.developmentontheedge.sql.model.AstStringConstant 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);
}
Aggregations