use of org.jooq.DatePart in project jOOQ by jOOQ.
the class DefaultParseContext method parseFieldTruncIf.
private final Field<?> parseFieldTruncIf() {
boolean forceNumericPrecision = false;
if (parseFunctionNameIf("TRUNC") || (forceNumericPrecision |= parseFunctionNameIf("TRUNCATE", "TRUNCNUM"))) {
parse('(');
Field<?> arg1 = parseField();
if (forceNumericPrecision && parse(',') || parseIf(',')) {
String part;
if (!forceNumericPrecision && (part = parseStringLiteralIf()) != null) {
part = part.toUpperCase();
DatePart p;
if ("YY".equals(part) || "YYYY".equals(part) || "YEAR".equals(part))
p = DatePart.YEAR;
else if ("MM".equals(part) || "MONTH".equals(part))
p = DatePart.MONTH;
else if ("DD".equals(part))
p = DatePart.DAY;
else if ("HH".equals(part))
p = DatePart.HOUR;
else if ("MI".equals(part))
p = DatePart.MINUTE;
else if ("SS".equals(part))
p = DatePart.SECOND;
else
throw exception("Unsupported date part");
parse(')');
return DSL.trunc((Field) arg1, p);
} else {
Field<?> arg2 = toField(parseNumericOp());
parse(')');
return DSL.trunc((Field) arg1, (Field) arg2);
}
}
parse(')');
// [#10668] Ignore TRUNC() when calling TRUNC(CURRENT_DATE) or TRUNC(SYSDATE) in Oracle
if (arg1 instanceof CurrentDate)
return arg1;
else if (arg1.getDataType().isDateTime())
return DSL.trunc((Field) arg1, DatePart.DAY);
else if (arg1.getDataType().isNumeric())
return DSL.trunc((Field) arg1, inline(0));
else
return DSL.trunc((Field) arg1);
}
return null;
}
use of org.jooq.DatePart in project jOOQ by jOOQ.
the class DefaultParseContext method parseSumRightOperand.
private final Field parseSumRightOperand(FieldOrRow r, boolean add) {
Field rhs = (Field) parseFactor();
DatePart part;
if (!ignoreProEdition() && (parseKeywordIf("YEAR") || parseKeywordIf("YEARS")) && requireProEdition())
part = DatePart.YEAR;
else if (!ignoreProEdition() && (parseKeywordIf("MONTH") || parseKeywordIf("MONTHS")) && requireProEdition())
part = DatePart.MONTH;
else if (!ignoreProEdition() && (parseKeywordIf("DAY") || parseKeywordIf("DAYS")) && requireProEdition())
part = DatePart.DAY;
else if (!ignoreProEdition() && (parseKeywordIf("HOUR") || parseKeywordIf("HOURS")) && requireProEdition())
part = DatePart.HOUR;
else if (!ignoreProEdition() && (parseKeywordIf("MINUTE") || parseKeywordIf("MINUTES")) && requireProEdition())
part = DatePart.MINUTE;
else if (!ignoreProEdition() && (parseKeywordIf("SECOND") || parseKeywordIf("SECONDS")) && requireProEdition())
part = DatePart.SECOND;
else
part = null;
Field lhs = (Field) r;
if (add)
return lhs.add(rhs);
else if (lhs.getDataType().isDate() && rhs.getDataType().isDate())
return DSL.dateDiff(lhs, rhs);
else if (lhs.getDataType().isTimestamp() && rhs.getDataType().isTimestamp())
return DSL.timestampDiff(lhs, rhs);
else
return lhs.sub(rhs);
}
use of org.jooq.DatePart in project jOOQ by jOOQ.
the class DefaultParseContext method parseFieldDateDiffIf.
private final Field<?> parseFieldDateDiffIf() {
if (parseFunctionNameIf("DATEDIFF")) {
parse('(');
DatePart datePart = parseDatePartIf();
if (datePart != null)
parse(',');
Field<Date> d1 = (Field<Date>) parseField();
if (parseIf(',')) {
Field<Date> d2 = (Field<Date>) parseField();
parse(')');
if (datePart != null)
return DSL.dateDiff(datePart, d1, d2);
else
return DSL.dateDiff(d1, d2);
}
parse(')');
if (datePart != null)
return DSL.dateDiff((Field) field(datePart.toName()), d1);
else
throw unsupportedClause();
}
return null;
}
use of org.jooq.DatePart in project jOOQ by jOOQ.
the class DefaultParseContext method parseFieldDatePartIf.
private final Field<?> parseFieldDatePartIf() {
if (parseFunctionNameIf("DATEPART")) {
parse('(');
DatePart part = parseDatePart();
parse(',');
Field<?> field = parseField();
parse(')');
return extract(field, part);
}
return null;
}
use of org.jooq.DatePart in project jOOQ by jOOQ.
the class DefaultParseContext method parseDatePartIf.
private final DatePart parseDatePartIf() {
int p = position();
boolean string = parseIf('\'');
DatePart result = parseDatePartIf0();
if (result == null)
position(p);
else if (string)
parse('\'');
// date part to a type explicitly
if (parseIf("::"))
parseDataType();
return result;
}
Aggregations