use of org.jooq.Insert in project jOOQ by jOOQ.
the class DefaultParseContext method parseInsert.
private final Query parseInsert(WithImpl with, boolean parseResultQuery) {
scopeStart();
parseKeyword("INSERT", "INS");
parseKeywordIf("INTO");
Table<?> table = parseTableNameIf();
if (table == null)
table = table(parseSelect());
Name alias;
if (parseKeywordIf("AS"))
table = table.as(parseIdentifier());
else if (!peekKeyword("DEFAULT VALUES", "SEL", "SELECT", "SET", "VALUES") && (alias = parseIdentifierIf()) != null)
table = table.as(alias);
scope(table);
InsertSetStep<?> s1 = (with == null ? dsl.insertInto(table) : with.insertInto(table));
Field<?>[] fields = null;
if (!peekSelectOrWith(true) && parseIf('(') && !parseIf(')')) {
fields = parseList(',', c -> parseField()).toArray(EMPTY_FIELD);
parse(')');
}
InsertOnDuplicateStep<?> onDuplicate;
InsertReturningStep<?> returning;
try {
// [#11821] The Teradata INSERT INTO t (1, 2) syntax can be recognised:
// When there are non-references fields
boolean hasExpressions = anyMatch(fields, f -> !(f instanceof TableField));
if (hasExpressions || parseKeywordIf("VALUES")) {
List<List<Field<?>>> allValues = new ArrayList<>();
if (hasExpressions) {
allValues.add(asList(fields));
fields = null;
}
valuesLoop: do {
if (hasExpressions && !parseIf(','))
break valuesLoop;
parse('(');
// [#6936] MySQL treats an empty VALUES() clause as the same thing as the standard DEFAULT VALUES
if (fields == null && parseIf(')'))
break valuesLoop;
List<Field<?>> values = parseList(',', c -> c.parseKeywordIf("DEFAULT") ? default_() : c.parseField());
if (fields != null && fields.length != values.size())
throw exception("Insert field size (" + fields.length + ") must match values size (" + values.size() + ")");
allValues.add(values);
parse(')');
} while (parseIf(','));
InsertValuesStepN<?> step2 = (fields != null) ? s1.columns(fields) : (InsertValuesStepN<?>) s1;
for (List<Field<?>> values : allValues) step2 = step2.values(values);
returning = onDuplicate = step2;
} else if (parseKeywordIf("SET")) {
Map<Field<?>, Object> map = parseSetClauseList();
returning = onDuplicate = s1.set(map);
} else if (peekSelectOrWith(true)) {
// [#10954] These are moved into the INSERT .. SELECT clause handling. They should not be necessary here
// either, but it seems we currently don't correctly implement nesting scopes?
scopeEnd(null);
scopeStart();
Select<?> select = parseWithOrSelect();
returning = onDuplicate = (fields == null) ? s1.select(select) : s1.columns(fields).select(select);
} else if (parseKeywordIf("DEFAULT VALUES")) {
if (fields != null)
throw notImplemented("DEFAULT VALUES without INSERT field list");
else
returning = onDuplicate = s1.defaultValues();
} else
throw expected("DEFAULT VALUES", "WITH", "SELECT", "SET", "VALUES");
if (parseKeywordIf("ON")) {
if (parseKeywordIf("DUPLICATE KEY UPDATE")) {
parseKeywordIf("SET");
InsertOnConflictWhereStep<?> where = onDuplicate.onDuplicateKeyUpdate().set(parseSetClauseList());
if (parseKeywordIf("WHERE"))
returning = where.where(parseCondition());
else
returning = where;
} else if (parseKeywordIf("DUPLICATE KEY IGNORE")) {
returning = onDuplicate.onDuplicateKeyIgnore();
} else if (parseKeywordIf("CONFLICT")) {
InsertOnConflictDoUpdateStep<?> doUpdate;
if (parseKeywordIf("ON CONSTRAINT")) {
doUpdate = onDuplicate.onConflictOnConstraint(parseName());
} else if (parseIf('(')) {
InsertOnConflictWhereIndexPredicateStep<?> where = onDuplicate.onConflict(parseList(',', c -> parseFieldName()));
parse(')');
doUpdate = parseKeywordIf("WHERE") ? where.where(parseCondition()) : where;
} else {
doUpdate = onDuplicate.onConflict();
}
parseKeyword("DO");
if (parseKeywordIf("NOTHING")) {
returning = doUpdate.doNothing();
} else if (parseKeywordIf("UPDATE SET")) {
InsertOnConflictWhereStep<?> where = doUpdate.doUpdate().set(parseSetClauseList());
if (parseKeywordIf("WHERE"))
returning = where.where(parseCondition());
else
returning = where;
} else
throw expected("NOTHING", "UPDATE");
} else
throw expected("CONFLICT", "DUPLICATE");
}
return (parseResultQuery ? parseKeyword("RETURNING") : parseKeywordIf("RETURNING")) ? returning.returning(parseSelectList()) : returning;
} finally {
scopeEnd(((InsertImpl) s1).getDelegate());
}
}
use of org.jooq.Insert in project jOOQ by jOOQ.
the class DefaultParseContext method parseTerm.
private final FieldOrRow parseTerm() {
FieldOrRow field;
Object value;
switch(characterUpper()) {
// [#8821] Known prefixes so far:
case ':':
case '@':
case '?':
if ((field = parseBindVariableIf()) != null)
return field;
break;
case '\'':
return inline(parseStringLiteral());
case '$':
if ((field = parseBindVariableIf()) != null)
return field;
else if ((value = parseDollarQuotedStringLiteralIf()) != null)
return inline((String) value);
break;
case 'A':
if (parseFunctionNameIf("ABS"))
return abs((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("ASC", "ASCII", "ASCII_VAL"))
return ascii((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("ACOS"))
return acos((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("ASIN"))
return asin((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("ATAN", "ATN"))
return atan((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("ATN2", "ATAN2"))
return parseFunctionArgs2(() -> toField(parseNumericOp()), DSL::atan2);
else if (parseFunctionNameIf("ASCII_CHAR"))
return chr((Field) parseFieldParenthesised());
else if ((field = parseArrayValueConstructorIf()) != null)
return field;
else if (parseFunctionNameIf("ADD_YEARS"))
return parseFieldAddDatePart(YEAR);
else if (parseFunctionNameIf("ADD_MONTHS"))
return parseFieldAddDatePart(MONTH);
else if (parseFunctionNameIf("ADD_DAYS"))
return parseFieldAddDatePart(DAY);
else if (parseFunctionNameIf("ADD_HOURS"))
return parseFieldAddDatePart(HOUR);
else if (parseFunctionNameIf("ADD_MINUTES"))
return parseFieldAddDatePart(MINUTE);
else if (parseFunctionNameIf("ADD_SECONDS"))
return parseFieldAddDatePart(SECOND);
else if (parseFunctionNameIf("ARRAY_GET"))
return parseFunctionArgs2((f1, f2) -> arrayGet(f1, f2));
break;
case 'B':
if (parseFunctionNameIf("BIT_LENGTH"))
return bitLength((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("BITCOUNT", "BIT_COUNT"))
return bitCount((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("BYTE_LENGTH"))
return octetLength((Field) parseFieldParenthesised());
else if ((field = parseFieldBitwiseFunctionIf()) != null)
return field;
else if ((value = parseBitLiteralIf()) != null)
return DSL.inline((Boolean) value);
break;
case 'C':
if ((field = parseFieldConcatIf()) != null)
return field;
else if ((parseFunctionNameIf("CURRENT_CATALOG") && parseEmptyParens()))
return currentCatalog();
else if ((parseFunctionNameIf("CURRENT_DATABASE") && parseEmptyParens()))
return currentCatalog();
else if ((parseKeywordIf("CURRENT_SCHEMA", "CURRENT SCHEMA")) && parseEmptyParensIf())
return currentSchema();
else if ((parseKeywordIf("CURRENT_USER", "CURRENT USER", "CURRENTUSER")) && parseEmptyParensIf())
return currentUser();
else if (parseFunctionNameIf("CHR", "CHAR"))
return chr((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("CHARINDEX"))
return parseFunctionArgs3((f1, f2) -> DSL.position(f2, f1), (f1, f2, f3) -> DSL.position(f2, f1, f3));
else if (parseFunctionNameIf("CHAR_LENGTH"))
return charLength((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("CARDINALITY"))
return cardinality((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("CEILING", "CEIL"))
return ceil((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("COSH"))
return cosh((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("COS"))
return cos((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("COTH"))
return coth((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("COT"))
return cot((Field) parseFieldNumericOpParenthesised());
else if ((field = parseNextvalCurrvalIf(SequenceMethod.CURRVAL)) != null)
return field;
else if (parseFunctionNameIf("CENTURY"))
return century(parseFieldParenthesised());
else if ((parseKeywordIf("CURRENT_DATE") || parseKeywordIf("CURRENT DATE")) && parseEmptyParensIf())
return currentDate();
else if (parseKeywordIf("CURRENT_TIMESTAMP") || parseKeywordIf("CURRENT TIMESTAMP")) {
Field<Integer> precision = null;
if (parseIf('('))
if (!parseIf(')')) {
precision = (Field<Integer>) parseField();
parse(')');
}
return precision != null ? currentTimestamp(precision) : currentTimestamp();
} else if ((parseKeywordIf("CURRENT_TIME") || parseKeywordIf("CURRENT TIME")) && parseEmptyParensIf())
return currentTime();
else if (parseFunctionNameIf("CURDATE") && parseEmptyParens())
return currentDate();
else if (parseFunctionNameIf("CURTIME") && parseEmptyParens())
return currentTime();
else if ((field = parseFieldCaseIf()) != null)
return field;
else if ((field = parseFieldCastIf()) != null)
return field;
else if ((field = parseFieldCoalesceIf()) != null)
return field;
else if ((field = parseFieldCumeDistIf()) != null)
return field;
else if ((field = parseFieldConvertIf()) != null)
return field;
else if ((field = parseFieldChooseIf()) != null)
return field;
else if (!ignoreProEdition() && parseKeywordIf("CONNECT_BY_ISCYCLE") && requireProEdition()) {
} else if (!ignoreProEdition() && parseKeywordIf("CONNECT_BY_ISLEAF") && requireProEdition()) {
}
break;
case 'D':
if ((parseFunctionNameIf("DATABASE") && parseEmptyParens()))
return currentCatalog();
else if ((parseFunctionNameIf("DB_NAME") && parseEmptyParens()))
return currentCatalog();
else if ((parseFunctionNameIf("DBINFO") && parse('(') && parseStringLiteral("dbname") != null && parse(')')))
return currentCatalog();
else if (parseFunctionNameIf("DIGITS"))
return digits((Field) parseFieldParenthesised());
else if ((field = parseFieldDateLiteralIf()) != null)
return field;
else if ((field = parseFieldDateTruncIf()) != null)
return field;
else if ((field = parseFieldDateAddIf()) != null)
return field;
else if ((field = parseFieldDateDiffIf()) != null)
return field;
else if ((field = parseFieldDatePartIf()) != null)
return field;
else if ((field = parseFieldDenseRankIf()) != null)
return field;
else if (parseFunctionNameIf("DECADE"))
return decade(parseFieldParenthesised());
else if (parseFunctionNameIf("DAY") || parseFunctionNameIf("DAYOFMONTH"))
return day(parseFieldParenthesised());
else // DB2 and MySQL support the non-ISO version where weeks go from Sunday = 1 to Saturday = 7
if (parseFunctionNameIf("DAYOFWEEK_ISO"))
return isoDayOfWeek(parseFieldParenthesised());
else if (parseFunctionNameIf("DAYOFWEEK") || parseFunctionNameIf("DAY_OF_WEEK"))
return dayOfWeek(parseFieldParenthesised());
else if (parseFunctionNameIf("DAYOFYEAR") || parseFunctionNameIf("DAY_OF_YEAR"))
return dayOfYear(parseFieldParenthesised());
else if (parseFunctionNameIf("DEGREES") || parseFunctionNameIf("DEGREE") || parseFunctionNameIf("DEG"))
return deg((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("DATALENGTH"))
return octetLength((Field) parseFieldParenthesised());
else if ((field = parseFieldDecodeIf()) != null)
return field;
else if (parseKeywordIf("DEFAULT"))
return default_();
break;
case 'E':
// [#6704] PostgreSQL E'...' escaped string literals
if (characterNext() == '\'')
return inline(parseStringLiteral());
else if ((field = parseFieldExtractIf()) != null)
return field;
else if (parseFunctionNameIf("EXP"))
return exp((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("EPOCH"))
return epoch(parseFieldParenthesised());
break;
case 'F':
if (parseFunctionNameIf("FLOOR"))
return floor((Field) parseFieldNumericOpParenthesised());
else if ((field = parseFieldFirstValueIf()) != null)
return field;
else if ((field = parseFieldFieldIf()) != null)
return field;
break;
case 'G':
if (parseKeywordIf("GETDATE") && parseEmptyParens())
return currentTimestamp();
else if (parseFunctionNameIf("GENGUID", "GENERATE_UUID", "GEN_RANDOM_UUID") && parseEmptyParens())
return uuid();
else if ((field = parseFieldGreatestIf()) != null)
return field;
else if (!ignoreProEdition() && parseFunctionNameIf("GROUP_ID") && requireProEdition() && parseEmptyParens()) {
} else if ((field = parseFieldGroupingIdIf()) != null)
return field;
else if (parseFunctionNameIf("GROUPING"))
return grouping(parseFieldParenthesised());
else if (!ignoreProEdition() && (parseFunctionNameIf("GEOMETRY::STGEOMFROMWKB") || parseFunctionNameIf("GEOGRAPHY::STGEOMFROMWKB")) && requireProEdition()) {
} else if (!ignoreProEdition() && (parseFunctionNameIf("GEOMETRY::STGEOMFROMTEXT") || parseFunctionNameIf("GEOGRAPHY::STGEOMFROMTEXT")) && requireProEdition()) {
} else
break;
case 'H':
if (parseFunctionNameIf("HOUR"))
return hour(parseFieldParenthesised());
else if (parseFunctionNameIf("HASH_MD5"))
return md5((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("HEX"))
return toHex((Field) parseFieldParenthesised());
break;
case 'I':
if ((field = parseFieldIntervalLiteralIf()) != null)
return field;
else if (parseFunctionNameIf("ISO_DAY_OF_WEEK"))
return isoDayOfWeek(parseFieldParenthesised());
else if (parseFunctionNameIf("INSTR"))
return parseFunctionArgs3(DSL::position, DSL::position);
else if (parseFunctionNameIf("INSERT"))
return parseFunctionArgs4(DSL::insert);
else if (parseFunctionNameIf("IFNULL"))
return parseFunctionArgs2((f1, f2) -> ifnull((Field<?>) f1, (Field<?>) f2));
else if (parseFunctionNameIf("ISNULL"))
return parseFunctionArgs2(f -> field(f.isNull()), (f1, f2) -> isnull((Field<?>) f1, (Field<?>) f2));
else if ((field = parseFieldIfIf()) != null)
return field;
else
break;
case 'J':
if ((field = parseFieldJSONArrayConstructorIf()) != null)
return field;
else if ((field = parseFieldJSONObjectConstructorIf()) != null)
return field;
else if ((field = parseFieldJSONValueIf()) != null)
return field;
else if ((field = parseFieldJSONLiteralIf()) != null)
return field;
break;
case 'L':
if (parseFunctionNameIf("LOWER", "LCASE"))
return lower((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("LPAD"))
return parseFunctionArgs3(DSL::lpad, DSL::lpad);
else if (parseFunctionNameIf("LTRIM"))
return parseFunctionArgs2(DSL::ltrim, DSL::ltrim);
else if (parseFunctionNameIf("LEFT"))
return parseFunctionArgs2(DSL::left);
else if (parseFunctionNameIf("LENGTH", "LEN"))
return length((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("LENGTHB"))
return octetLength((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("LN", "LOGN"))
return ln((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("LOG10"))
return log10((Field) parseFieldNumericOpParenthesised());
else if ((field = parseFieldLogIf()) != null)
return field;
else if ((field = parseFieldLocateIf()) != null)
return field;
else if (!ignoreProEdition() && parseKeywordIf("LEVEL") && requireProEdition()) {
} else if (parseKeywordIf("LSHIFT"))
return parseFunctionArgs2(() -> toField(parseNumericOp()), (f1, f2) -> shl(f1, f2));
else if ((field = parseFieldLeastIf()) != null)
return field;
else if ((field = parseFieldLeadLagIf()) != null)
return field;
else if ((field = parseFieldLastValueIf()) != null)
return field;
break;
case 'M':
if (parseFunctionNameIf("MOD"))
return parseFunctionArgs2(Field::mod);
else if (parseFunctionNameIf("MICROSECOND"))
return microsecond(parseFieldParenthesised());
else if (parseFunctionNameIf("MILLENNIUM"))
return millennium(parseFieldParenthesised());
else if (parseFunctionNameIf("MILLISECOND"))
return millisecond(parseFieldParenthesised());
else if (parseFunctionNameIf("MINUTE"))
return minute(parseFieldParenthesised());
else if (parseFunctionNameIf("MONTH"))
return month(parseFieldParenthesised());
else if (parseFunctionNameIf("MID"))
return parseFunctionArgs3(DSL::mid);
else if (parseFunctionNameIf("MD5"))
return md5((Field) parseFieldParenthesised());
else if ((field = parseMultisetValueConstructorIf()) != null)
return field;
else if ((field = parseFieldGreatestIf()) != null)
return field;
else if ((field = parseFieldLeastIf()) != null)
return field;
else if ((field = parseFieldDecodeIf()) != null)
return field;
break;
case 'N':
// [#9540] N'...' NVARCHAR literals
if (characterNext() == '\'')
return inline(parseStringLiteral(), NVARCHAR);
else if ((field = parseFieldNewIdIf()) != null)
return field;
else if (parseFunctionNameIf("NVL2"))
return parseFunctionArgs3((f1, f2, f3) -> nvl2((Field<?>) f1, (Field<?>) f2, (Field<?>) f3));
else if (parseFunctionNameIf("NVL"))
return parseFunctionArgs2((f1, f2) -> nvl((Field<?>) f1, (Field<?>) f2));
else if (parseFunctionNameIf("NULLIF"))
return parseFunctionArgs2((f1, f2) -> nullif((Field<?>) f1, (Field<?>) f2));
else if ((field = parseFieldNtileIf()) != null)
return field;
else if ((field = parseFieldNthValueIf()) != null)
return field;
else if ((field = parseNextValueIf()) != null)
return field;
else if ((field = parseNextvalCurrvalIf(SequenceMethod.NEXTVAL)) != null)
return field;
else if (parseFunctionNameIf("NOW") && parse('(')) {
if (parseIf(')'))
return now();
Field<Integer> precision = (Field<Integer>) parseField();
parse(')');
return now(precision);
}
break;
case 'O':
if (parseFunctionNameIf("OREPLACE"))
return parseFunctionArgs3(DSL::replace, DSL::replace);
else if ((field = parseFieldOverlayIf()) != null)
return field;
else if ((field = parseFieldTranslateIf()) != null)
return field;
else if (parseFunctionNameIf("OCTET_LENGTH"))
return octetLength((Field) parseFieldParenthesised());
break;
case 'P':
if ((field = parseFieldPositionIf()) != null)
return field;
else if ((field = parseFieldPercentRankIf()) != null)
return field;
else if (parseFunctionNameIf("POWER", "POW"))
return parseFunctionArgs2(() -> toField(parseNumericOp()), DSL::power);
else if (parseFunctionNameIf("PI") && parseEmptyParens())
return pi();
else if (!ignoreProEdition() && parseKeywordIf("PRIOR") && requireProEdition()) {
}
break;
case 'Q':
if (characterNext() == '\'')
return inline(parseStringLiteral());
else if (parseFunctionNameIf("QUARTER"))
return quarter(parseFieldParenthesised());
case 'R':
if (parseFunctionNameIf("REPLACE"))
return parseFunctionArgs3(DSL::replace, DSL::replace);
else if ((field = parseFieldRegexpReplaceIf()) != null)
return field;
else if (parseFunctionNameIf("REPEAT", "REPLICATE"))
return parseFunctionArgs2(DSL::repeat);
else if (parseFunctionNameIf("REVERSE"))
return reverse((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("RPAD"))
return parseFunctionArgs3(DSL::rpad, DSL::rpad);
else if (parseFunctionNameIf("RTRIM"))
return parseFunctionArgs2(DSL::rtrim, DSL::rtrim);
else if (parseFunctionNameIf("RIGHT"))
return parseFunctionArgs2(DSL::right);
else if (parseFunctionNameIf("RANDOM_UUID") && parseEmptyParens())
return uuid();
else if (parseFunctionNameIf("ROW_NUMBER") && parseEmptyParens())
return parseWindowFunction(null, null, rowNumber());
else if ((field = parseFieldRankIf()) != null)
return field;
else if ((field = parseFieldRoundIf()) != null)
return field;
else if (!ignoreProEdition() && parseKeywordIf("ROWNUM") && requireProEdition()) {
} else if (parseFunctionNameIf("RADIANS") || parseFunctionNameIf("RADIAN") || parseFunctionNameIf("RAD"))
return rad((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("RAND", "RANDOM") && parseEmptyParens())
return rand();
else if (parseFunctionNameIf("RATIO_TO_REPORT"))
return parseFunctionArgs1(f -> parseWindowFunction(null, null, ratioToReport(f)));
else if (parseKeywordIf("RSHIFT"))
return parseFunctionArgs2(() -> toField(parseNumericOp()), (f1, f2) -> shr(f1, f2));
else if (parseFunctionNameIf("ROW"))
return parseTuple();
break;
case 'S':
if ((field = parseFieldSubstringIf()) != null)
return field;
else if (parseFunctionNameIf("SUBSTRING_INDEX"))
return parseFunctionArgs3(DSL::substringIndex);
else if (parseFunctionNameIf("SPACE"))
return space((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("SPLIT_PART"))
return parseFunctionArgs3(DSL::splitPart);
else if (parseFunctionNameIf("STR_REPLACE"))
return parseFunctionArgs3(DSL::replace, DSL::replace);
else if (parseFunctionNameIf("SCHEMA") && parseEmptyParensIf())
return currentSchema();
else if (parseFunctionNameIf("STRREVERSE"))
return reverse((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("SYSUUID") && parseEmptyParensIf())
return uuid();
else if (parseFunctionNameIf("SECOND"))
return second(parseFieldParenthesised());
else if (!ignoreProEdition() && parseFunctionNameIf("SEQ4", "SEQ8") && parseEmptyParens() && requireProEdition()) {
} else if (parseFunctionNameIf("SIGN", "SGN"))
return sign((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("SQRT", "SQR"))
return sqrt((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("SQUARE"))
return square((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("SINH"))
return sinh((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("SIN"))
return sin((Field) parseFieldNumericOpParenthesised());
else if (parseKeywordIf("SHL", "SHIFTLEFT"))
return parseFunctionArgs2(() -> toField(parseNumericOp()), (f1, f2) -> shl(f1, f2));
else if (parseKeywordIf("SHR", "SHIFTRIGHT"))
return parseFunctionArgs2(() -> toField(parseNumericOp()), (f1, f2) -> shr(f1, f2));
else if ((field = parseFieldSysConnectByPathIf()) != null)
return field;
else if (!ignoreProEdition() && parseFunctionNameIf("ST_AREA") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_AREA") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_ASBINARY") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_ASTEXT") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_CENTROID") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_CENTROID") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_DIFFERENCE") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_DIFFERENCE") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_DISTANCE") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_DISTANCE") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_ENDPOINT") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_EXTERIORRING") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_GEOMETRYN") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_GEOMETRYTYPE") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_GEOMFROMWKB") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_GEOMFROMTEXT", "SDO_GEOMETRY") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_INTERIORRINGN") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_INTERSECTION") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_INTERSECTION") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_LENGTH") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_LENGTH") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_NUMINTERIORRING", "ST_NUMINTERIORRINGS") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_NUMGEOMETRIES", "SDO_UTIL.GETNUMELEM") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_NUMPOINTS") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_POINTN") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_SRID") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_STARTPOINT") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_UNION") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("SDO_GEOM.SDO_UNION") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_X") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_Y") && requireProEdition()) {
} else if (!ignoreProEdition() && parseFunctionNameIf("ST_Z") && requireProEdition()) {
}
break;
case 'T':
if ((field = parseBooleanValueExpressionIf()) != null)
return field;
else if ((field = parseFieldTrimIf()) != null)
return field;
else if ((field = parseFieldTranslateIf()) != null)
return field;
else if (parseFunctionNameIf("TO_CHAR"))
return parseFunctionArgs2(DSL::toChar, DSL::toChar);
else if (parseFunctionNameIf("TO_HEX"))
return toHex((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("TANH"))
return tanh((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("TAN"))
return tan((Field) parseFieldNumericOpParenthesised());
else if (parseFunctionNameIf("TO_NUMBER"))
return parseFunctionArgs1(f -> cast(f, NUMERIC));
else if (parseFunctionNameIf("TIMEZONE_HOUR"))
return timezoneHour(parseFieldParenthesised());
else if (parseFunctionNameIf("TIMEZONE_MINUTE"))
return timezoneMinute(parseFieldParenthesised());
else if (parseFunctionNameIf("TIMEZONE"))
return timezone(parseFieldParenthesised());
else if ((field = parseFieldTimestampLiteralIf()) != null)
return field;
else if ((field = parseFieldTimeLiteralIf()) != null)
return field;
else if (parseFunctionNameIf("TO_DATE"))
return parseFunctionArgs2(f1 -> toDate(f1, inline(settings().getParseDateFormat())), DSL::toDate);
else if (parseFunctionNameIf("TO_TIMESTAMP"))
return parseFunctionArgs2(f1 -> toTimestamp(f1, inline(settings().getParseTimestampFormat())), DSL::toTimestamp);
else if (parseFunctionNameIf("TIMESTAMPDIFF"))
return parseFunctionArgs2((f1, f2) -> DSL.timestampDiff(f1, f2));
else if ((field = parseFieldTruncIf()) != null)
return field;
break;
case 'U':
if (parseFunctionNameIf("UPPER", "UCASE"))
return DSL.upper((Field) parseFieldParenthesised());
else if (parseFunctionNameIf("UUID", "UUID_GENERATE", "UUID_STRING") && parseEmptyParens())
return uuid();
else if (parseFunctionNameIf("UNIX_TIMESTAMP"))
return epoch(parseFieldParenthesised());
break;
case 'W':
if (parseFunctionNameIf("WIDTH_BUCKET"))
return parseFunctionArgs4((f1, f2, f3, f4) -> widthBucket(f1, f2, f3, f4));
else if (parseFunctionNameIf("WEEK"))
return week(parseFieldParenthesised());
break;
case 'X':
if ((value = parseBinaryLiteralIf()) != null)
return inline((byte[]) value);
else if (parseFunctionNameIf("XMLCOMMENT"))
return xmlcomment((Field) parseField());
else if ((field = parseFieldXMLConcatIf()) != null)
return field;
else if ((field = parseFieldXMLElementIf()) != null)
return field;
else if ((field = parseFieldXMLPIIf()) != null)
return field;
else if ((field = parseFieldXMLForestIf()) != null)
return field;
else if ((field = parseFieldXMLParseIf()) != null)
return field;
else if ((field = parseFieldXMLDocumentIf()) != null)
return field;
else if ((field = parseFieldXMLQueryIf()) != null)
return field;
else if ((field = parseFieldXMLSerializeIf()) != null)
return field;
break;
case 'Y':
if (parseFunctionNameIf("YEAR"))
return year(parseFieldParenthesised());
break;
case 'Z':
if (parseFunctionNameIf("ZEROIFNULL"))
return coalesce(parseFieldParenthesised(), zero());
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
case '.':
if ((field = parseFieldUnsignedNumericLiteralIf(Sign.NONE)) != null)
return field;
break;
case '{':
parse('{', false);
switch(characterUpper()) {
case 'D':
parseKeyword("D");
field = inline(parseDateLiteral());
break;
case 'F':
parseKeyword("FN");
// TODO: Limit the supported expressions in this context to the ones specified here:
// http://download.oracle.com/otn-pub/jcp/jdbc-4_2-mrel2-eval-spec/jdbc4.2-fr-spec.pdf
field = parseTerm();
break;
case 'T':
if (parseKeywordIf("TS")) {
field = inline(parseTimestampLiteral());
} else {
parseKeyword("T");
field = inline(parseTimeLiteral());
}
break;
default:
throw exception("Unsupported JDBC escape literal");
}
parse('}');
return field;
case '(':
// A term parenthesis can mark the beginning of any of:
// - ROW expression without ROW keyword: E.g. (1, 2)
// - Parenthesised field expression: E.g. (1 + 2)
// - A correlated subquery: E.g. (select 1)
// - A correlated subquery with nested set ops: E.g. ((select 1) except (select 2))
// - A combination of the above: E.g. ((select 1) + 2, ((select 1) except (select 2)) + 2)
int p = position();
EnumSet fk = forbidden;
try {
if (!forbidden.isEmpty())
forbidden = EnumSet.noneOf(FunctionKeyword.class);
FieldOrRow r = parseScalarSubqueryIf();
if (r != null)
return r;
parse('(');
r = parseFieldOrRow();
List<Field<?>> list = null;
if (r instanceof Field) {
Field<?> f = (Field<?>) r;
while (parseIf(',')) {
if (list == null) {
list = new ArrayList<>();
list.add(f);
}
// TODO Allow for nesting ROWs
list.add(parseField());
}
}
parse(')');
return list != null ? row(list) : r;
} finally {
forbidden = fk;
}
}
if ((field = parseAggregateFunctionIf()) != null)
return field;
else if ((field = parseBooleanValueExpressionIf()) != null)
return field;
else
return parseFieldNameOrSequenceExpression();
}
use of org.jooq.Insert in project jOOQ by jOOQ.
the class DefaultParseContext method parseTableFactor.
private final Table<?> parseTableFactor(BooleanSupplier forbiddenKeywords) {
// [#7982] Postpone turning Select into a Table in case there is an alias
TableLike<?> result;
// TODO ONLY ( table primary )
if (parseFunctionNameIf("OLD TABLE")) {
parse('(');
Query query = parseQuery(false, false);
parse(')');
if (query instanceof Merge)
result = oldTable((Merge<?>) query);
else if (query instanceof Update)
result = oldTable((Update<?>) query);
else if (query instanceof Delete)
result = oldTable((Delete<?>) query);
else
throw expected("UPDATE", "DELETE", "MERGE");
} else if (parseFunctionNameIf("NEW TABLE")) {
parse('(');
Query query = parseQuery(false, false);
parse(')');
if (query instanceof Merge)
result = newTable((Merge<?>) query);
else if (query instanceof Insert)
result = newTable((Insert<?>) query);
else if (query instanceof Update)
result = newTable((Update<?>) query);
else
throw expected("INSERT", "UPDATE", "MERGE");
} else if (parseFunctionNameIf("FINAL TABLE")) {
parse('(');
Query query = parseQuery(false, false);
parse(')');
if (query instanceof Merge)
result = finalTable((Merge<?>) query);
else if (query instanceof Insert)
result = finalTable((Insert<?>) query);
else if (query instanceof Update)
result = finalTable((Update<?>) query);
else
throw expected("INSERT", "UPDATE", "MERGE");
} else if (parseFunctionNameIf("UNNEST", "TABLE")) {
parse('(');
if (parseFunctionNameIf("GENERATOR")) {
parse('(');
Field<?> tl = parseFunctionArgumentIf("TIMELIMIT");
Field<?> rc = parseFunctionArgumentIf("ROWCOUNT");
if (tl == null)
tl = parseFunctionArgumentIf("TIMELIMIT");
parse(')');
result = generateSeries(one(), (Field<Integer>) rc);
} else {
Field<?> f = parseField();
// Work around a missing feature in unnest()
if (!f.getType().isArray())
f = f.coerce(f.getDataType().getArrayDataType());
result = unnest(f);
}
parse(')');
} else if (parseFunctionNameIf("GENERATE_SERIES", "SYSTEM_RANGE")) {
parse('(');
Field from = toField(parseConcat());
parse(',');
Field to = toField(parseConcat());
Field step = parseIf(',') ? toField(parseConcat()) : null;
parse(')');
result = step == null ? generateSeries(from, to) : generateSeries(from, to, step);
} else if (parseFunctionNameIf("JSON_TABLE")) {
parse('(');
Field json = parseField();
parse(',');
Field path = toField(parseConcat());
JSONTableColumnsStep s1 = (JSONTableColumnsStep) jsonTable(json, path);
parseKeyword("COLUMNS");
parse('(');
do {
Name fieldName = parseIdentifier();
if (parseKeywordIf("FOR ORDINALITY")) {
s1 = s1.column(fieldName).forOrdinality();
} else {
JSONTableColumnPathStep s2 = s1.column(fieldName, parseDataType());
s1 = parseKeywordIf("PATH") ? s2.path(parseStringLiteral()) : s2;
}
} while (parseIf(','));
parse(')');
parse(')');
result = s1;
} else if (peekFunctionNameIf("VALUES")) {
result = parseTableValueConstructor();
} else if (parseFunctionNameIf("XMLTABLE")) {
parse('(');
XMLTablePassingStep s1 = xmltable((Field) toField(parseConcat()));
XMLPassingMechanism m = parseXMLPassingMechanismIf();
Field<XML> passing = m == null ? null : (Field<XML>) parseField();
XMLTableColumnsStep s2 = (XMLTableColumnsStep) (m == BY_REF ? s1.passingByRef(passing) : m == BY_VALUE ? s1.passingByValue(passing) : m == XMLPassingMechanism.DEFAULT ? s1.passing(passing) : s1);
parseKeyword("COLUMNS");
do {
Name fieldName = parseIdentifier();
if (parseKeywordIf("FOR ORDINALITY")) {
s2 = s2.column(fieldName).forOrdinality();
} else {
XMLTableColumnPathStep s3 = s2.column(fieldName, parseDataType());
s2 = parseKeywordIf("PATH") ? s3.path(parseStringLiteral()) : s3;
}
} while (parseIf(','));
parse(')');
result = s2;
} else if (parseIf('(')) {
// - A combination of the above: E.g. ((a join (select 1) on p) right join (((select 1)) union (select 2)) on q)
if (peekKeyword("SELECT", "SEL", "WITH")) {
SelectQueryImpl<Record> select = parseWithOrSelect();
parse(')');
result = parseQueryExpressionBody(null, null, select);
} else if (peekKeyword("VALUES")) {
result = parseTableValueConstructor();
parse(')');
} else {
result = parseJoinedTable(forbiddenKeywords);
parse(')');
}
} else {
result = parseTableName();
// TODO Sample clause
}
if (!ignoreProEdition() && parseKeywordIf("VERSIONS BETWEEN") && requireProEdition()) {
} else if (!ignoreProEdition() && peekKeyword("FOR") && !peekKeyword("FOR JSON") && !peekKeyword("FOR KEY SHARE") && !peekKeyword("FOR NO KEY UPDATE") && !peekKeyword("FOR SHARE") && !peekKeyword("FOR UPDATE") && !peekKeyword("FOR XML") && parseKeyword("FOR") && requireProEdition()) {
} else if (!ignoreProEdition() && parseKeywordIf("AS OF") && requireProEdition()) {
}
if (!ignoreProEdition() && parseKeywordIf("PIVOT") && requireProEdition()) {
}
// TODO UNPIVOT
result = parseCorrelationNameIf(result, forbiddenKeywords);
int p = position();
if (parseKeywordIf("WITH")) {
if (!ignoreProEdition() && parseIf('(') && requireProEdition()) {
} else
// [#10164] Without parens, WITH is part of the next statement in delimiter free statement batches
position(p);
}
return t(result);
}
Aggregations