use of org.jooq.impl.SQLDataType.BOOLEAN 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.impl.SQLDataType.BOOLEAN in project jOOQ by jOOQ.
the class DefaultParseContext method parseCreateTable.
private final DDLQuery parseCreateTable(boolean temporary) {
boolean ifNotExists = parseKeywordIf("IF NOT EXISTS");
Table<?> tableName = DSL.table(parseTableName().getQualifiedName());
if (parseKeywordIf("USING"))
parseIdentifier();
CreateTableOnCommitStep onCommitStep;
CreateTableCommentStep commentStep;
List<Field<?>> fields = new ArrayList<>();
List<Constraint> constraints = new ArrayList<>();
List<Index> indexes = new ArrayList<>();
boolean primary = false;
boolean identity = false;
boolean readonly = false;
boolean ctas = false;
if (!peekSelectOrWith(true) && parseIf('(')) {
columnLoop: do {
int p = position();
ConstraintTypeStep constraint = parseConstraintNameSpecification();
if (parsePrimaryKeyClusteredNonClusteredKeywordIf()) {
if (primary)
throw exception("Duplicate primary key specification");
primary = true;
constraints.add(parsePrimaryKeySpecification(constraint));
continue columnLoop;
} else if (parseKeywordIf("UNIQUE")) {
if (!parseKeywordIf("KEY"))
parseKeywordIf("INDEX");
// [#9132] Avoid parsing "using" as an identifier
parseUsingIndexTypeIf();
// [#7268] MySQL has some legacy syntax where an index name
// can override a constraint name
Name index = parseIdentifierIf();
if (index != null)
constraint = constraint(index);
constraints.add(parseUniqueSpecification(constraint));
continue columnLoop;
} else if (parseKeywordIf("FOREIGN KEY")) {
constraints.add(parseForeignKeySpecification(constraint));
continue columnLoop;
} else if (parseKeywordIf("CHECK")) {
constraints.add(parseCheckSpecification(constraint));
continue columnLoop;
} else if (constraint == null && parseIndexOrKeyIf()) {
parseUsingIndexTypeIf();
int p2 = position();
// Look ahead if the next tokens indicate a MySQL index definition
if (parseIf('(') || (parseDataTypeIf(false) == null && parseIdentifierIf() != null && parseUsingIndexTypeIf() && parseIf('('))) {
position(p2);
indexes.add(parseIndexSpecification(tableName));
parseUsingIndexTypeIf();
continue columnLoop;
} else {
position(p);
}
} else if (constraint != null)
throw expected("CHECK", "CONSTRAINT", "FOREIGN KEY", "INDEX", "KEY", "PRIMARY KEY", "UNIQUE");
Name fieldName = parseIdentifier();
boolean skipType = peek(',') || peek(')');
// If only we had multiple return values or destructuring...
ParseInlineConstraints inlineConstraints = parseInlineConstraints(fieldName, !skipType ? parseDataType() : SQLDataType.OTHER, constraints, primary, identity, readonly);
primary = inlineConstraints.primary;
identity = inlineConstraints.identity;
fields.add(field(fieldName, inlineConstraints.type, inlineConstraints.fieldComment));
} while (parseIf(','));
if (fields.isEmpty())
throw expected("At least one column");
parse(')');
} else
ctas = true;
CreateTableElementListStep elementListStep = ifNotExists ? temporary ? dsl.createTemporaryTableIfNotExists(tableName) : dsl.createTableIfNotExists(tableName) : temporary ? dsl.createTemporaryTable(tableName) : dsl.createTable(tableName);
if (!fields.isEmpty())
elementListStep = elementListStep.columns(fields);
CreateTableElementListStep constraintStep = constraints.isEmpty() ? elementListStep : elementListStep.constraints(constraints);
CreateTableAsStep asStep = indexes.isEmpty() ? constraintStep : constraintStep.indexes(indexes);
// [#6133] Historically, the jOOQ API places the ON COMMIT clause after
// the AS clause, which doesn't correspond to dialect implementations
Function<CreateTableOnCommitStep, CreateTableCommentStep> onCommit;
if (temporary && parseKeywordIf("ON COMMIT")) {
if (parseKeywordIf("DELETE ROWS"))
onCommit = CreateTableOnCommitStep::onCommitDeleteRows;
else if (parseKeywordIf("DROP"))
onCommit = CreateTableOnCommitStep::onCommitDrop;
else if (parseKeywordIf("PRESERVE ROWS"))
onCommit = CreateTableOnCommitStep::onCommitPreserveRows;
else
throw unsupportedClause();
} else
onCommit = s -> s;
// keyword only for empty field lists
if (parseKeywordIf("AS") || fields.isEmpty() && peekSelectOrWith(true)) {
boolean previousMetaLookupsForceIgnore = metaLookupsForceIgnore();
CreateTableWithDataStep withDataStep = asStep.as((Select<Record>) metaLookupsForceIgnore(false).parseQuery(true, true));
metaLookupsForceIgnore(previousMetaLookupsForceIgnore);
onCommitStep = parseKeywordIf("WITH DATA") ? withDataStep.withData() : parseKeywordIf("WITH NO DATA") ? withDataStep.withNoData() : withDataStep;
} else if (ctas)
throw expected("AS, WITH, SELECT, or (");
else
onCommitStep = asStep;
commentStep = onCommit.apply(onCommitStep);
List<SQL> storage = new ArrayList<>();
Comment comment = null;
storageLoop: for (boolean first = true; ; first = false) {
boolean optional = first || !parseIf(',');
Keyword keyword = null;
// MySQL storage clauses (see: https://dev.mysql.com/doc/refman/5.7/en/create-table.html)
if ((keyword = parseAndGetKeywordIf("AUTO_INCREMENT")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseFieldUnsignedNumericLiteral(Sign.NONE)));
} else if ((keyword = parseAndGetKeywordIf("AVG_ROW_LENGTH")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseFieldUnsignedNumericLiteral(Sign.NONE)));
} else if ((keyword = parseAndGetKeywordIf("CHARACTER SET")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseIdentifier()));
} else if ((keyword = parseAndGetKeywordIf("DEFAULT CHARACTER SET")) != null || (keyword = parseAndGetKeywordIf("DEFAULT CHARSET")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseIdentifier()));
} else if ((keyword = parseAndGetKeywordIf("CHECKSUM")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseZeroOne()));
} else if ((keyword = parseAndGetKeywordIf("COLLATE")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseIdentifier()));
} else if ((keyword = parseAndGetKeywordIf("DEFAULT COLLATE")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseIdentifier()));
} else // [#10164] In a statement batch, this could already be the next statement
if (!peekKeyword("COMMENT ON") && parseKeywordIf("COMMENT")) {
if (!parseIf('='))
parseKeywordIf("IS");
comment = parseComment();
} else if (peekKeyword("OPTIONS")) {
comment = parseOptionsDescription();
} else if ((keyword = parseAndGetKeywordIf("COMPRESSION")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseStringLiteral()));
} else if ((keyword = parseAndGetKeywordIf("CONNECTION")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseStringLiteral()));
} else if ((keyword = parseAndGetKeywordIf("DATA DIRECTORY")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseStringLiteral()));
} else if ((keyword = parseAndGetKeywordIf("INDEX DIRECTORY")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseStringLiteral()));
} else if ((keyword = parseAndGetKeywordIf("DELAY_KEY_WRITE")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseZeroOne()));
} else if ((keyword = parseAndGetKeywordIf("ENCRYPTION")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseStringLiteral()));
} else if ((keyword = parseAndGetKeywordIf("ENGINE")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseIdentifier()));
} else if ((keyword = parseAndGetKeywordIf("INSERT_METHOD")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseAndGetKeyword("NO", "FIRST", "LAST")));
} else if ((keyword = parseAndGetKeywordIf("KEY_BLOCK_SIZE")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseFieldUnsignedNumericLiteral(Sign.NONE)));
} else if ((keyword = parseAndGetKeywordIf("MAX_ROWS")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseFieldUnsignedNumericLiteral(Sign.NONE)));
} else if ((keyword = parseAndGetKeywordIf("MIN_ROWS")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseFieldUnsignedNumericLiteral(Sign.NONE)));
} else if ((keyword = parseAndGetKeywordIf("PACK_KEYS")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseZeroOneDefault()));
} else if ((keyword = parseAndGetKeywordIf("PASSWORD")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseStringLiteral()));
} else if ((keyword = parseAndGetKeywordIf("ROW_FORMAT")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseAndGetKeyword("DEFAULT", "DYNAMIC", "FIXED", "COMPRESSED", "REDUNDANT", "COMPACT")));
} else if ((keyword = parseAndGetKeywordIf("STATS_AUTO_RECALC")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseZeroOneDefault()));
} else if ((keyword = parseAndGetKeywordIf("STATS_PERSISTENT")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseZeroOneDefault()));
} else if ((keyword = parseAndGetKeywordIf("STATS_SAMPLE_PAGES")) != null) {
parseIf('=');
storage.add(sql("{0} {1}", keyword, parseFieldUnsignedNumericLiteral(Sign.NONE)));
} else if ((keyword = parseAndGetKeywordIf("TABLESPACE")) != null) {
storage.add(sql("{0} {1}", keyword, parseIdentifier()));
if ((keyword = parseAndGetKeywordIf("STORAGE")) != null)
storage.add(sql("{0} {1}", keyword, parseAndGetKeyword("DISK", "MEMORY", "DEFAULT")));
} else if ((keyword = parseAndGetKeywordIf("UNION")) != null) {
parseIf('=');
parse('(');
storage.add(sql("{0} ({1})", keyword, list(parseIdentifiers())));
parse(')');
} else if (optional)
break storageLoop;
else
throw expected("storage clause after ','");
}
CreateTableStorageStep storageStep = comment != null ? commentStep.comment(comment) : commentStep;
if (storage.size() > 0)
return storageStep.storage(new SQLConcatenationImpl(storage.toArray(EMPTY_QUERYPART)));
else
return storageStep;
}
Aggregations