diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 8cd506d720..bfccecc85e 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -229,6 +229,8 @@ public class Settings @XmlElement(defaultValue = "OFF") @XmlSchemaType(name = "string") protected ParseWithMetaLookups parseWithMetaLookups = ParseWithMetaLookups.OFF; + @XmlElement(defaultValue = "false") + protected Boolean parseSetCommands = false; @XmlElement(defaultValue = "IGNORE") @XmlSchemaType(name = "string") protected ParseUnsupportedSyntax parseUnsupportedSyntax = ParseUnsupportedSyntax.IGNORE; @@ -1951,6 +1953,30 @@ public class Settings this.parseWithMetaLookups = value; } + /** + * [#9780] Whether commands of the type SET key = value should be parsed rather than ignored. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isParseSetCommands() { + return parseSetCommands; + } + + /** + * Sets the value of the parseSetCommands property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setParseSetCommands(Boolean value) { + this.parseSetCommands = value; + } + /** * [#5917] Whether the parser should accept unsupported (but known) syntax. * @@ -2688,6 +2714,11 @@ public class Settings return this; } + public Settings withParseSetCommands(Boolean value) { + setParseSetCommands(value); + return this; + } + /** * [#5917] Whether the parser should accept unsupported (but known) syntax. * @@ -2852,6 +2883,7 @@ public class Settings builder.append("parseLocale", parseLocale); builder.append("parseNameCase", parseNameCase); builder.append("parseWithMetaLookups", parseWithMetaLookups); + builder.append("parseSetCommands", parseSetCommands); builder.append("parseUnsupportedSyntax", parseUnsupportedSyntax); builder.append("parseUnknownFunctions", parseUnknownFunctions); builder.append("parseIgnoreComments", parseIgnoreComments); @@ -3591,6 +3623,15 @@ public class Settings return false; } } + if (parseSetCommands == null) { + if (other.parseSetCommands!= null) { + return false; + } + } else { + if (!parseSetCommands.equals(other.parseSetCommands)) { + return false; + } + } if (parseUnsupportedSyntax == null) { if (other.parseUnsupportedSyntax!= null) { return false; @@ -3740,6 +3781,7 @@ public class Settings result = ((prime*result)+((parseLocale == null)? 0 :parseLocale.hashCode())); result = ((prime*result)+((parseNameCase == null)? 0 :parseNameCase.hashCode())); result = ((prime*result)+((parseWithMetaLookups == null)? 0 :parseWithMetaLookups.hashCode())); + result = ((prime*result)+((parseSetCommands == null)? 0 :parseSetCommands.hashCode())); result = ((prime*result)+((parseUnsupportedSyntax == null)? 0 :parseUnsupportedSyntax.hashCode())); result = ((prime*result)+((parseUnknownFunctions == null)? 0 :parseUnknownFunctions.hashCode())); result = ((prime*result)+((parseIgnoreComments == null)? 0 :parseIgnoreComments.hashCode())); diff --git a/jOOQ/src/main/java/org/jooq/impl/Interpreter.java b/jOOQ/src/main/java/org/jooq/impl/Interpreter.java index 318f9188d2..8b45088310 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Interpreter.java +++ b/jOOQ/src/main/java/org/jooq/impl/Interpreter.java @@ -102,6 +102,7 @@ import org.jooq.conf.InterpreterSearchSchema; import org.jooq.exception.DataAccessException; import org.jooq.exception.DataDefinitionException; import org.jooq.impl.ConstraintImpl.Action; +import org.jooq.tools.Convert; import org.jooq.tools.JooqLogger; @SuppressWarnings("serial") @@ -225,6 +226,9 @@ final class Interpreter { else if (query instanceof Merge) ; + else if (query instanceof SetCommand) + accept0((SetCommand) query); + else throw unsupportedQuery(query); } @@ -1003,6 +1007,13 @@ final class Interpreter { currentSchema = schema; } + private final void accept0(SetCommand query) { + if ("foreign_key_checks".equals(query.$name().last().toLowerCase(locale))) + delayForeignKeyDeclarations = !Convert.convert(query.$value().getValue(), boolean.class); + else + throw unsupportedQuery(query); + } + // ------------------------------------------------------------------------- // Exceptions // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index e15d52554e..2532c0e1df 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -2017,10 +2017,27 @@ final class ParserImpl implements Parser { return parseSetSchema(ctx); else if (parseKeywordIf(ctx, "SEARCH_PATH")) return parseSetSearchPath(ctx); + else + return parseSetCommand(ctx); + } + + private static final Query parseSetCommand(ParserContext ctx) { + if (TRUE.equals(ctx.settings().isParseSetCommands())) { + Name name = parseIdentifier(ctx); + + // TODO: [#9780] Are there any possible syntaxes and data types? + parseIf(ctx, '='); + Object value = parseSignedIntegerIf(ctx); + + // TODO: [#9781] Create public DSL API for this + return new SetCommand(ctx.dsl.configuration(), name, value != null ? inline(value) : inline(parseStringLiteral(ctx))); + } // There are many SET commands in programs like sqlplus, which we'll simply ignore - parseUntilEOL(ctx); - return IGNORE_NO_DELIMITER; + else { + parseUntilEOL(ctx); + return IGNORE_NO_DELIMITER; + } } private static final Query parseSetCatalog(ParserContext ctx) { diff --git a/jOOQ/src/main/java/org/jooq/impl/SetCommand.java b/jOOQ/src/main/java/org/jooq/impl/SetCommand.java new file mode 100644 index 0000000000..2f25d16622 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/SetCommand.java @@ -0,0 +1,80 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.impl.Keywords.K_SET; + +import org.jooq.Configuration; +import org.jooq.Context; +import org.jooq.Name; +import org.jooq.Param; + +/** + * A SET command. + * + * @author Lukas Eder + */ +final class SetCommand extends AbstractQuery { + + /** + * Generated UID + */ + private static final long serialVersionUID = -6018875346107141474L; + + private final Name name; + private final Param value; + + SetCommand(Configuration configuration, Name name, Param value) { + super(configuration); + + this.name = name; + this.value = value; + } + + final Name $name() { return name; } + final Param $value() { return value; } + + // ------------------------------------------------------------------------ + // XXX: QueryPart API + // ------------------------------------------------------------------------ + + @Override + public final void accept(Context ctx) { + ctx.visit(K_SET).sql(' ').visit(name).sql(" = ").visit(value); + } +} diff --git a/jOOQ/src/main/resources/xsd/jooq-runtime-3.13.0.xsd b/jOOQ/src/main/resources/xsd/jooq-runtime-3.13.0.xsd index abb700491c..38abf3d984 100644 --- a/jOOQ/src/main/resources/xsd/jooq-runtime-3.13.0.xsd +++ b/jOOQ/src/main/resources/xsd/jooq-runtime-3.13.0.xsd @@ -479,6 +479,10 @@ jOOQ queries, for which no specific fetchSize value was specified.]]> + + SET key = value should be parsed rather than ignored.]]> + +