use of org.jooq.DatePart in project jOOQ by jOOQ.
the class ParserImpl method parseFieldExtractIf.
private static final Field<?> parseFieldExtractIf(ParserContext ctx) {
if (parseKeywordIf(ctx, "EXTRACT")) {
parse(ctx, '(');
DatePart part = parseDatePart(ctx);
parseKeyword(ctx, "FROM");
Field<?> field = parseField(ctx);
parse(ctx, ')');
return extract(field, part);
}
return null;
}
use of org.jooq.DatePart in project jOOQ by jOOQ.
the class DefaultParseContext method parseFieldExtractIf.
private final Field<?> parseFieldExtractIf() {
if (parseFunctionNameIf("EXTRACT")) {
parse('(');
DatePart part = parseDatePart();
parseKeyword("FROM");
Field<?> field = parseField();
parse(')');
return extract(field, part);
}
return null;
}
use of org.jooq.DatePart in project jOOQ by jOOQ.
the class DefaultParseContext method parseFieldDateTruncIf.
private final Field<?> parseFieldDateTruncIf() {
if (parseFunctionNameIf("DATE_TRUNC", "DATETIME_TRUNC")) {
parse('(');
Field<?> field;
DatePart part;
switch(parseFamily()) {
default:
part = parseDatePart();
parse(',');
field = parseField();
break;
}
parse(')');
return trunc(field, part);
}
return null;
}
use of org.jooq.DatePart in project jOOQ by jOOQ.
the class DefaultParseContext method parseFieldIntervalLiteralIf.
private final Field<?> parseFieldIntervalLiteralIf() {
int p = position();
if (parseKeywordIf("INTERVAL")) {
if (peek('\'')) {
return inline(parseIntervalLiteral());
} else {
Long interval = parseUnsignedIntegerLiteralIf();
if (interval != null) {
DatePart part = parseIntervalDatePart();
long l = interval;
int i = asInt(l);
switch(part) {
case YEAR:
return inline(new YearToMonth(i));
case QUARTER:
return inline(new YearToMonth(0, 3 * i));
case MONTH:
return inline(new YearToMonth(0, i));
case WEEK:
return inline(new DayToSecond(7 * i));
case DAY:
return inline(new DayToSecond(i));
case HOUR:
return inline(new DayToSecond(0, i));
case MINUTE:
return inline(new DayToSecond(0, 0, i));
case SECOND:
return inline(new DayToSecond(0, 0, 0, i));
case MILLISECOND:
return inline(new DayToSecond(0, 0, 0, asInt(l / 1000), (int) (l % 1000 * 1000000)));
case MICROSECOND:
return inline(new DayToSecond(0, 0, 0, asInt(l / 1000000), (int) (l % 1000000 * 1000)));
case NANOSECOND:
return inline(new DayToSecond(0, 0, 0, asInt(l / 1000000000), (int) (l % 1000000000)));
}
} else {
position(p);
return field(parseIdentifier());
}
}
}
return null;
}
use of org.jooq.DatePart in project jOOQ by jOOQ.
the class DefaultParseContext method parseFieldDateAddIf.
private final Field<?> parseFieldDateAddIf() {
boolean sub = false;
// SQL Server style
if (parseFunctionNameIf("DATEADD")) {
parse('(');
DatePart part = parseDatePart();
parse(',');
Field<Number> interval = (Field<Number>) parseField();
parse(',');
Field<Date> date = (Field<Date>) parseField();
parse(')');
return DSL.dateAdd(date, interval, part);
} else // MySQL style
if (parseFunctionNameIf("DATE_ADD") || (sub = parseFunctionNameIf("DATE_SUB"))) {
parse('(');
Field<?> d = parseField();
// [#12025] In the absence of meta data, assume TIMESTAMP
Field<?> date = d.getDataType().isDateTime() ? d : d.coerce(TIMESTAMP);
parse(',');
// [#8792] TODO: Support parsing interval expressions
Field<?> interval = parseFieldIntervalLiteralIf();
parse(')');
return sub ? DSL.dateSub((Field) date, (Field) interval) : DSL.dateAdd((Field) date, (Field) interval);
}
return null;
}
Aggregations