[jOOQ/jOOQ#8660] Add support for synthetic ALTER TABLE .. DROP PRIMARY KEY <name> syntax
This commit is contained in:
parent
b62b8bf0a2
commit
cdf8ea7381
@ -593,19 +593,60 @@ public interface AlterTableStep {
|
||||
AlterTableFinalStep dropPrimaryKey();
|
||||
|
||||
/**
|
||||
* Add a <code>DROP FOREIGN KEY</code> clause to the <code>ALTER TABLE</code>
|
||||
* Add a <code>DROP PRIMARY KEY</code> clause to the
|
||||
* <code>ALTER TABLE</code> statement.
|
||||
* <p>
|
||||
* Dialect families derived from MySQL do not know named constraints, in
|
||||
* case of which this clause simply generates <code>DROP PRIMARY KEY</code>
|
||||
* as in {@link #dropPrimaryKey()}. In other dialect families, this produces
|
||||
* a <code>DROP CONSTRAINT [name]</code> clause, as in
|
||||
* {@link #dropConstraint(Constraint)}.
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
AlterTableFinalStep dropPrimaryKey(Constraint constraint);
|
||||
|
||||
/**
|
||||
* Add a <code>DROP PRIMARY KEY</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
* <p>
|
||||
* Dialect families derived from MySQL do not know named constraints, in
|
||||
* case of which this clause simply generates <code>DROP PRIMARY KEY</code>
|
||||
* as in {@link #dropPrimaryKey()}. In other dialect families, this produces
|
||||
* a <code>DROP CONSTRAINT [name]</code> clause, as in
|
||||
* {@link #dropConstraint(Name)}.
|
||||
*
|
||||
* @see DSL#constraint(Name)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
AlterTableFinalStep dropPrimaryKey(Name constraint);
|
||||
|
||||
/**
|
||||
* Add a <code>DROP PRIMARY KEY</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
* <p>
|
||||
* Dialect families derived from MySQL do not know named constraints, in
|
||||
* case of which this clause simply generates <code>DROP PRIMARY KEY</code>
|
||||
* as in {@link #dropPrimaryKey()}. In other dialect families, this produces
|
||||
* a <code>DROP CONSTRAINT [name]</code> clause, as in
|
||||
* {@link #dropConstraint(String)}.
|
||||
*
|
||||
* @see DSL#constraint(String)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
AlterTableFinalStep dropPrimaryKey(String constraint);
|
||||
|
||||
/**
|
||||
* Add a <code>DROP FOREIGN KEY</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
AlterTableFinalStep dropForeignKey(Constraint constraint);
|
||||
|
||||
/**
|
||||
* Add a <code>DROP FOREIGN KEY</code> clause to the <code>ALTER TABLE</code>
|
||||
* statement.
|
||||
*
|
||||
* @see DSL#constraint(String)
|
||||
* @see DSL#constraint(Name)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
AlterTableFinalStep dropForeignKey(Name constraint);
|
||||
|
||||
@ -704,6 +704,23 @@ final class AlterTableImpl extends AbstractRowCountQuery implements
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AlterTableImpl dropPrimaryKey(Constraint constraint) {
|
||||
dropConstraint = constraint;
|
||||
dropConstraintType = PRIMARY_KEY;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AlterTableImpl dropPrimaryKey(Name constraint) {
|
||||
return dropPrimaryKey(constraint(constraint));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AlterTableImpl dropPrimaryKey(String constraint) {
|
||||
return dropPrimaryKey(constraint(constraint));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AlterTableImpl dropForeignKey(Constraint constraint) {
|
||||
dropConstraint = constraint;
|
||||
@ -1311,6 +1328,8 @@ final class AlterTableImpl extends AbstractRowCountQuery implements
|
||||
ctx.visit(K_DROP).sql(' ').visit(K_FOREIGN_KEY)
|
||||
.sql(' ')
|
||||
.visit(dropConstraint);
|
||||
else if (dropConstraintType == PRIMARY_KEY && NO_SUPPORT_DROP_CONSTRAINT.contains(family))
|
||||
ctx.visit(K_DROP).sql(' ').visit(K_PRIMARY_KEY);
|
||||
else
|
||||
ctx.visit(K_DROP_CONSTRAINT)
|
||||
.sql(' ')
|
||||
|
||||
@ -3612,7 +3612,8 @@ final class ParserImpl implements Parser {
|
||||
return s1.dropConstraint(parseIdentifier(ctx));
|
||||
}
|
||||
else if (parseKeywordIf(ctx, "PRIMARY KEY")) {
|
||||
return s1.dropPrimaryKey();
|
||||
Name identifier = parseIdentifierIf(ctx);
|
||||
return identifier == null ? s1.dropPrimaryKey() : s1.dropPrimaryKey(identifier);
|
||||
}
|
||||
else if (parseKeywordIf(ctx, "FOREIGN KEY")) {
|
||||
return s1.dropForeignKey(parseIdentifier(ctx));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user