use of com.developmentontheedge.sql.model.AstIdentifierConstant 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.AstIdentifierConstant 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.AstIdentifierConstant 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.AstIdentifierConstant in project be5 by DevelopmentOnTheEdge.
the class Be5QueryExecutor method countFromQuery.
private void countFromQuery(AstQuery query) {
AstSelect select = Ast.selectCount().from(AstTableRef.as(new AstParenthesis(query.clone()), new AstIdentifierConstant("data", true)));
query.replaceWith(new AstQuery(select));
}
use of com.developmentontheedge.sql.model.AstIdentifierConstant in project be5 by DevelopmentOnTheEdge.
the class LimitsApplier method transformQuery.
public boolean transformQuery(AstQuery query) {
if (query.jjtGetNumChildren() == 1) {
AstSelect select = (AstSelect) query.child(0);
if (select.getLimit() != null)
return false;
AstLimit limit = new AstLimit();
limit.setLimit(offset, count);
select.addChild(limit);
} else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
AstSelect select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
AstLimit limit = new AstLimit();
limit.setLimit(offset, count);
select.addChild(limit);
query.replaceWith(new AstQuery(select));
}
// TODO: support offset, union, etc.
return true;
}
Aggregations