[#6485] [#7116] Add parser support for COLLATE clause

This commit is contained in:
lukaseder 2018-01-30 13:22:56 +01:00
parent 20d1e08133
commit 20f802254a
2 changed files with 25 additions and 3 deletions

View File

@ -498,7 +498,10 @@ predicate =
row2 = [ 'ROW' ] '(' field ',' field ')'
;
concat = sum { '||' sum }
concat = collated { '||' collated }
;
collated = sum [ 'COLLATE' collation ]
;
sum = factor { ( '+' | '-' ) factor }
@ -789,6 +792,9 @@ fieldNames = fieldName { ',' fieldName }
fieldName = name
;
collation = name
;
name = identifier { '.' identifier }
;

View File

@ -58,6 +58,7 @@ import static org.jooq.impl.DSL.charLength;
import static org.jooq.impl.DSL.check;
import static org.jooq.impl.DSL.choose;
import static org.jooq.impl.DSL.coalesce;
import static org.jooq.impl.DSL.collation;
import static org.jooq.impl.DSL.concat;
import static org.jooq.impl.DSL.condition;
import static org.jooq.impl.DSL.constraint;
@ -259,6 +260,7 @@ import org.jooq.CaseConditionStep;
import org.jooq.CaseValueStep;
import org.jooq.CaseWhenStep;
import org.jooq.Catalog;
import org.jooq.Collation;
import org.jooq.Comment;
import org.jooq.CommentOnIsStep;
import org.jooq.CommonTableExpression;
@ -3424,11 +3426,21 @@ final class ParserImpl implements Parser {
}
private static final FieldOrRow parseConcat(ParserContext ctx, Type type) {
FieldOrRow r = parseSum(ctx, type);
FieldOrRow r = parseCollated(ctx, type);
if (S.is(type) && r instanceof Field)
while (parseIf(ctx, "||"))
r = concat((Field) r, toField(ctx, parseSum(ctx, type)));
r = concat((Field) r, toField(ctx, parseCollated(ctx, type)));
return r;
}
private static final FieldOrRow parseCollated(ParserContext ctx, Type type) {
FieldOrRow r = parseSum(ctx, type);
if (S.is(type) && r instanceof Field)
if (parseKeywordIf(ctx, "COLLATE"))
r = ((Field) r).collate(parseCollation(ctx));
return r;
}
@ -5746,6 +5758,10 @@ final class ParserImpl implements Parser {
return null;
}
private static final Collation parseCollation(ParserContext ctx) {
return collation(parseName(ctx));
}
private static final Name parseName(ParserContext ctx) {
Name result = parseNameIf(ctx);