Skip to content

Commit

Permalink
[#5955] Oracle doubly parenthesised ROW expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Apr 17, 2017
1 parent c249962 commit 1bef9d4
Showing 1 changed file with 62 additions and 8 deletions.
70 changes: 62 additions & 8 deletions jOOQ/src/main/java/org/jooq/impl/ParserImpl.java
Expand Up @@ -2013,7 +2013,23 @@ private static final RowN parseTuple(ParserContext ctx, Integer degree) {


private static final RowN parseTuple(ParserContext ctx, Integer degree, boolean allowDoubleParens) { private static final RowN parseTuple(ParserContext ctx, Integer degree, boolean allowDoubleParens) {
parse(ctx, '('); parse(ctx, '(');
RowN row = row(parseFields(ctx)); List<? extends FieldOrRow> fieldsOrRows;

if (allowDoubleParens)
fieldsOrRows = parseFieldsOrRows(ctx);
else
fieldsOrRows = parseFields(ctx);

RowN row;

if (fieldsOrRows.size() == 0)
row = row();
else if (fieldsOrRows.get(0) instanceof Field)
row = row(fieldsOrRows);
else if (fieldsOrRows.size() == 1)
row = (RowN) fieldsOrRows.get(0);
else
throw ctx.exception();


if (degree != null && row.size() != degree) if (degree != null && row.size() != degree)
throw ctx.exception(); throw ctx.exception();
Expand Down Expand Up @@ -2135,10 +2151,25 @@ private static final List<Field<?>> parseFields(ParserContext ctx) {
return result; return result;
} }


private static final List<FieldOrRow> parseFieldsOrRows(ParserContext ctx) {
parseWhitespaceIf(ctx);

List<FieldOrRow> result = new ArrayList<FieldOrRow>();
do {
result.add(parseFieldOrRow(ctx));
}
while (parseIf(ctx, ','));
return result;
}

private static final Field<?> parseField(ParserContext ctx) { private static final Field<?> parseField(ParserContext ctx) {
return parseField(ctx, null); return parseField(ctx, null);
} }


private static final FieldOrRow parseFieldOrRow(ParserContext ctx) {
return parseFieldOrRow(ctx, null);
}

private static final RowN parseRow(ParserContext ctx) { private static final RowN parseRow(ParserContext ctx) {
return parseRow(ctx, null); return parseRow(ctx, null);
} }
Expand Down Expand Up @@ -2189,6 +2220,13 @@ boolean is(Type type) {
} }
} }


private static final FieldOrRow parseFieldOrRow(ParserContext ctx, Type type) {
if (B.is(type))
return toFieldOrRow(ctx, parseOr(ctx));
else
return parseConcat(ctx, type);
}

private static final Field<?> parseField(ParserContext ctx, Type type) { private static final Field<?> parseField(ParserContext ctx, Type type) {
if (B.is(type)) if (B.is(type))
return toField(ctx, parseOr(ctx)); return toField(ctx, parseOr(ctx));
Expand All @@ -2210,6 +2248,19 @@ else if (part instanceof Field)
throw ctx.exception(); throw ctx.exception();
} }


private static final FieldOrRow toFieldOrRow(ParserContext ctx, QueryPart part) {
if (part == null)
return null;
else if (part instanceof Field)
return (Field) part;
else if (part instanceof Condition)
return field((Condition) part);
else if (part instanceof Row)
return (Row) part;
else
throw ctx.exception();
}

private static final Field<?> toField(ParserContext ctx, QueryPart part) { private static final Field<?> toField(ParserContext ctx, QueryPart part) {
if (part == null) if (part == null)
return null; return null;
Expand Down Expand Up @@ -2672,16 +2723,19 @@ else if ((field = parseFieldTimeLiteralIf(ctx)) != null)
return field; return field;
} }
else { else {
Field<?> r = parseField(ctx, type); FieldOrRow r = parseFieldOrRow(ctx, type);
List<Field<?>> list = null; List<Field<?>> list = null;


while (parseIf(ctx, ',')) { if (r instanceof Field) {
if (list == null) { while (parseIf(ctx, ',')) {
list = new ArrayList<Field<?>>(); if (list == null) {
list.add(r); list = new ArrayList<Field<?>>();
} list.add((Field) r);
}


list.add(parseField(ctx, type)); // TODO Allow for nesting ROWs
list.add(parseField(ctx, type));
}
} }


parse(ctx, ')'); parse(ctx, ')');
Expand Down

0 comments on commit 1bef9d4

Please sign in to comment.