[#5955] Add support for WITH TIES clauses

This commit is contained in:
lukaseder 2017-05-09 17:40:11 +02:00
parent f30cfa1d92
commit 64deb3a4e2

View File

@ -619,12 +619,24 @@ class ParserImpl implements Parser {
if (!offsetStandard && parseKeywordIf(ctx, "LIMIT")) {
Param<Integer> limit = inline((int) (long) parseUnsignedInteger(ctx));
if (!offsetPostgres && parseIf(ctx, ','))
result.addLimit(limit, inline((int) (long) parseUnsignedInteger(ctx)));
else if (!offsetPostgres && parseKeywordIf(ctx, "OFFSET"))
result.addLimit(inline((int) (long) parseUnsignedInteger(ctx)), limit);
else
if (offsetPostgres) {
result.addLimit(limit);
if (parseKeywordIf(ctx, "WITH TIES"))
result.setWithTies(true);
}
else if (parseIf(ctx, ',')) {
result.addLimit(limit, inline((int) (long) parseUnsignedInteger(ctx)));
}
else {
if (parseKeywordIf(ctx, "WITH TIES"))
result.setWithTies(true);
if (parseKeywordIf(ctx, "OFFSET"))
result.addLimit(inline((int) (long) parseUnsignedInteger(ctx)), limit);
else
result.addLimit(limit);
}
}
else if (!offsetPostgres && parseKeywordIf(ctx, "FETCH")) {
if (!parseKeywordIf(ctx, "FIRST") && !parseKeywordIf(ctx, "NEXT"))
@ -632,8 +644,13 @@ class ParserImpl implements Parser {
result.addLimit(inline((int) (long) parseUnsignedInteger(ctx)));
if (!parseKeywordIf(ctx, "ROWS ONLY") && !parseKeywordIf(ctx, "ROW ONLY"))
if (!parseKeywordIf(ctx, "ROW") && !parseKeywordIf(ctx, "ROWS"))
throw ctx.unexpectedToken();
if (parseKeywordIf(ctx, "WITH TIES"))
result.setWithTies(true);
else
parseKeyword(ctx, "ONLY");
}
}
@ -690,6 +707,7 @@ class ParserImpl implements Parser {
Long limit = null;
Long offset = null;
boolean withTies = false;
// T-SQL style TOP .. START AT
if (parseKeywordIf(ctx, "TOP")) {
@ -697,6 +715,8 @@ class ParserImpl implements Parser {
if (parseKeywordIf(ctx, "START AT"))
offset = parseUnsignedInteger(ctx);
else if (parseKeywordIf(ctx, "WITH TIES"))
withTies = true;
}
// Informix style SKIP .. FIRST
@ -835,6 +855,9 @@ class ParserImpl implements Parser {
else
result.addLimit((int) (long) limit);
if (withTies)
result.setWithTies(true);
return result;
}