[jOOQ/jOOQ#16979] Exception when doing Meta.ddl() export with tables

that have USE or GO or similar field or table aliases
This commit is contained in:
Lukas Eder 2024-08-05 16:39:34 +02:00
parent 5e737fd626
commit bb2d386bdf
2 changed files with 14 additions and 3 deletions

View File

@ -74,6 +74,7 @@ import java.util.regex.Pattern;
import org.jooq.Check;
import org.jooq.Comment;
import org.jooq.Configuration;
import org.jooq.Constraint;
import org.jooq.ConstraintEnforcementStep;
import org.jooq.CreateDomainAsStep;
@ -214,7 +215,12 @@ final class DDL {
try {
if (!FALSE.equals(ctx.settings().isParseMetaViewSources())) {
Query[] queries = ctx.parser().parse(options.source()).queries();
// [#16979] Internal, undocumented flag to prevent
// [#17013] TODO: Use new Settings instead, once implemented
Configuration c = ctx.configuration().derive();
c.data("org.jooq.parser.delimiter-required", true);
Query[] queries = c.dsl().parser().parse(options.source()).queries();
if (queries.length > 0) {
if (queries[0] instanceof CreateViewImpl<?> cv)

View File

@ -7268,7 +7268,10 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
@Override
public final Table<?> parseTable() {
return parseJoinedTable(() -> peekKeyword(KEYWORD_LOOKUP_IN_SELECT_FROM));
return parseJoinedTable(() -> peekKeyword(delimiterRequired
? KEYWORD_LOOKUP_IN_FROM
: KEYWORD_LOOKUP_IN_SELECT_FROM
));
}
private final Table<?> parseLateral(BooleanSupplier forbiddenKeywords) {
@ -8093,7 +8096,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
if (parseKeywordIf("AS"))
alias = parseIdentifier(true, false);
else if (!peekKeyword(KEYWORD_LOOKUP_IN_SELECT) && !peekKeyword(KEYWORD_LOOKUP_IN_STATEMENTS))
else if (!peekKeyword(KEYWORD_LOOKUP_IN_SELECT) && (delimiterRequired || !peekKeyword(KEYWORD_LOOKUP_IN_STATEMENTS)))
alias = parseIdentifierIf(true, false);
}
@ -15684,6 +15687,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
private int bindIndex = 0;
private final Map<String, Param<?>> bindParams = new LinkedHashMap<>();
private String delimiter = ";";
private boolean delimiterRequired = false;
private LanguageContext languageContext = LanguageContext.QUERY;
private EnumSet<FunctionKeyword> forbidden = EnumSet.noneOf(FunctionKeyword.class);
private ParseScope scope = new ParseScope();
@ -15720,6 +15724,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
// [#8722] This is an undocumented flag that allows for collecting parameters from the parser
// Do not rely on this flag. It will change incompatibly in the future.
this.bindParamListener = (Consumer<Param<?>>) dsl.configuration().data("org.jooq.parser.param-collector");
this.delimiterRequired = TRUE.equals(dsl.configuration().data("org.jooq.parser.delimiter-required"));