if (add) {
function.setName("dateadd"); //$NON-NLS-1$
} else {
function.setName("datediff"); //$NON-NLS-1$
}
Literal intervalType = (Literal)function.getParameters().get(0);
String interval = ((String)intervalType.getValue()).toUpperCase();
String newInterval = INTERVAL_MAP.get(interval);
if (newInterval != null) {
intervalType.setValue(newInterval);
return null;
}
if (add) {
if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
intervalType.setValue("MILLISECOND"); //$NON-NLS-1$
Expression[] args = new Expression[] {function.getParameters().get(1), factory.createLiteral(1000000, TypeFacility.RUNTIME_TYPES.INTEGER)};
function.getParameters().set(1, factory.createFunction("/", args, TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
} else if (interval.equals(NonReserved.SQL_TSI_QUARTER)) {
intervalType.setValue(ExtractFunctionModifier.DAY);
Expression[] args = new Expression[] {function.getParameters().get(1), factory.createLiteral(91, TypeFacility.RUNTIME_TYPES.INTEGER)};
function.getParameters().set(1, factory.createFunction("*", args, TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
} else {
intervalType.setValue(ExtractFunctionModifier.DAY);
Expression[] args = new Expression[] {function.getParameters().get(1), factory.createLiteral(7, TypeFacility.RUNTIME_TYPES.INTEGER)};
function.getParameters().set(1, factory.createFunction("*", args, TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
}
return null;
}
if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
intervalType.setValue("MILLISECOND"); //$NON-NLS-1$
return Arrays.asList(function, " * 1000000"); //$NON-NLS-1$
} else if (interval.equals(NonReserved.SQL_TSI_QUARTER)) {
intervalType.setValue(ExtractFunctionModifier.DAY);
return Arrays.asList(function, " / 91"); //$NON-NLS-1$
}
intervalType.setValue(ExtractFunctionModifier.DAY);
return Arrays.asList(function, " / 7"); //$NON-NLS-1$
}