diff --git a/jOOQ/src/main/java/org/jooq/AlterTableStep.java b/jOOQ/src/main/java/org/jooq/AlterTableStep.java index c07c80f91a..8758eb2876 100644 --- a/jOOQ/src/main/java/org/jooq/AlterTableStep.java +++ b/jOOQ/src/main/java/org/jooq/AlterTableStep.java @@ -586,7 +586,14 @@ public interface AlterTableStep { AlterTableFinalStep dropConstraint(String constraint); /** - * Add a DROP CONSTRAINT clause to the ALTER TABLE + * Add a DROP PRIMARY KEY clause to the ALTER TABLE + * statement. + */ + @Support({ MARIADB, MYSQL }) + AlterTableFinalStep dropPrimaryKey(); + + /** + * Add a DROP FOREIGN KEY clause to the ALTER TABLE * statement. * * @see DSL#constraint(String) @@ -595,7 +602,7 @@ public interface AlterTableStep { AlterTableFinalStep dropForeignKey(Constraint constraint); /** - * Add a DROP CONSTRAINT clause to the ALTER TABLE + * Add a DROP FOREIGN KEY clause to the ALTER TABLE * statement. * * @see DSL#constraint(String) @@ -604,7 +611,7 @@ public interface AlterTableStep { AlterTableFinalStep dropForeignKey(Name constraint); /** - * Add a DROP CONSTRAINT clause to the ALTER TABLE + * Add a DROP FOREIGN KEY clause to the ALTER TABLE * statement. * * @see DSL#constraint(String) diff --git a/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java b/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java index 08b1c63b53..413d921e2f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/AlterTableImpl.java @@ -71,6 +71,7 @@ import static org.jooq.SQLDialect.POSTGRES; // ... // ... import static org.jooq.impl.ConstraintType.FOREIGN_KEY; +import static org.jooq.impl.ConstraintType.PRIMARY_KEY; import static org.jooq.impl.DSL.commentOnTable; import static org.jooq.impl.DSL.constraint; import static org.jooq.impl.DSL.field; @@ -104,6 +105,7 @@ import static org.jooq.impl.Keywords.K_LIKE; import static org.jooq.impl.Keywords.K_MODIFY; import static org.jooq.impl.Keywords.K_NOT_NULL; import static org.jooq.impl.Keywords.K_NULL; +import static org.jooq.impl.Keywords.K_PRIMARY_KEY; import static org.jooq.impl.Keywords.K_RAISE; import static org.jooq.impl.Keywords.K_RENAME; import static org.jooq.impl.Keywords.K_RENAME_COLUMN; @@ -686,6 +688,12 @@ final class AlterTableImpl extends AbstractRowCountQuery implements return dropConstraint(DSL.constraint(constraint)); } + @Override + public final AlterTableImpl dropPrimaryKey() { + dropConstraintType = PRIMARY_KEY; + return this; + } + @Override public final AlterTableImpl dropForeignKey(Constraint constraint) { dropConstraint = constraint; @@ -1271,6 +1279,11 @@ final class AlterTableImpl extends AbstractRowCountQuery implements ctx.data().remove(DATA_CONSTRAINT_REFERENCE); ctx.end(ALTER_TABLE_DROP); } + else if (dropConstraintType == PRIMARY_KEY) { + ctx.start(ALTER_TABLE_DROP); + ctx.visit(K_DROP).sql(' ').visit(K_PRIMARY_KEY); + ctx.end(ALTER_TABLE_DROP); + } if (!omitAlterTable) ctx.formatIndentEnd(); diff --git a/jOOQ/src/main/java/org/jooq/impl/ConstraintType.java b/jOOQ/src/main/java/org/jooq/impl/ConstraintType.java new file mode 100644 index 0000000000..9fccc7efcd --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/ConstraintType.java @@ -0,0 +1,48 @@ +/* + * 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; + +/** + * @author Lukas Eder + */ +enum ConstraintType { + PRIMARY_KEY, + UNIQUE, + FOREIGN_KEY, + CHECK +} diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index d297dfcc88..3f9184ff8b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -3611,6 +3611,9 @@ final class ParserImpl implements Parser { if (parseKeywordIf(ctx, "CONSTRAINT")) { return s1.dropConstraint(parseIdentifier(ctx)); } + else if (parseKeywordIf(ctx, "PRIMARY KEY")) { + return s1.dropPrimaryKey(); + } else if (parseKeywordIf(ctx, "FOREIGN KEY")) { return s1.dropForeignKey(parseIdentifier(ctx)); }