DROP VIEW IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSL#dropViewIfExists(Table)
+ */
+ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
+ DropViewFinalStep dropViewIfExists(Table> table);
+
+ /**
+ * Create a new DSL DROP VIEW IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSL#dropViewIfExists(String)
+ */
+ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
+ DropViewFinalStep dropViewIfExists(String table);
+
/**
* Create a new DSL DROP TABLE statement.
*
@@ -4933,6 +4956,28 @@ public interface DSLContext {
@Support
DropTableStep dropTable(String table);
+ /**
+ * Create a new DSL DROP TABLE IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSL#dropTableIfExists(Table)
+ */
+ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
+ DropTableStep dropTableIfExists(Table> table);
+
+ /**
+ * Create a new DSL ALTER TABLE IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSL#dropTableIfExists(String)
+ */
+ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
+ DropTableStep dropTableIfExists(String table);
+
/**
* Create a new DSL DROP INDEX statement.
*
@@ -4941,10 +4986,21 @@ public interface DSLContext {
@Support
DropIndexFinalStep dropIndex(String index);
+ /**
+ * Create a new DSL DROP INDEX IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSL#dropIndexIfExists(String)
+ */
+ @Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
+ DropIndexFinalStep dropIndexIfExists(String index);
+
/**
* Create a new DSL DROP SEQUENCE statement.
*
- * @see DSLContext#dropSequence(Sequence)
+ * @see DSL#dropSequence(Sequence)
*/
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
DropSequenceFinalStep dropSequence(Sequence> sequence);
@@ -4952,11 +5008,33 @@ public interface DSLContext {
/**
* Create a new DSL DROP SEQUENCE statement.
*
- * @see DSLContext#dropSequence(Sequence)
+ * @see DSL#dropSequence(String)
*/
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
DropSequenceFinalStep dropSequence(String sequence);
+ /**
+ * Create a new DSL DROP SEQUENCE IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSL#dropSequenceIfExists(Sequence)
+ */
+ @Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
+ DropSequenceFinalStep dropSequenceIfExists(Sequence> sequence);
+
+ /**
+ * Create a new DSL DROP SEQUENCE IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSL#dropSequenceIfExists(String)
+ */
+ @Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
+ DropSequenceFinalStep dropSequenceIfExists(String sequence);
+
/**
* Create a new DSL truncate statement.
*
diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java
index 8cbde96edb..4245ede6ed 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DSL.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java
@@ -4341,6 +4341,32 @@ public class DSL {
return using(new DefaultConfiguration()).dropView(table);
}
+ /**
+ * Create a new DSL DROP VIEW IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSLContext#dropViewIfExists(Table)
+ */
+ @Support
+ public static DropViewFinalStep dropViewIfExists(Table> table) {
+ return using(new DefaultConfiguration()).dropViewIfExists(table);
+ }
+
+ /**
+ * Create a new DSL DROP VIEW IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSLContext#dropViewIfExists(String)
+ */
+ @Support
+ public static DropViewFinalStep dropViewIfExists(String table) {
+ return using(new DefaultConfiguration()).dropViewIfExists(table);
+ }
+
/**
* Create a new DSL DROP TABLE statement.
*
@@ -4357,6 +4383,32 @@ public class DSL {
* @see DSLContext#dropTable(String)
*/
@Support
+ public static DropTableStep dropTableIfExists(String table) {
+ return using(new DefaultConfiguration()).dropTableIfExists(table);
+ }
+
+ /**
+ * Create a new DSL DROP TABLE IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSLContext#dropTableIfExists(Table)
+ */
+ @Support
+ public static DropTableStep dropTableIfExists(Table> table) {
+ return using(new DefaultConfiguration()).dropTableIfExists(table);
+ }
+
+ /**
+ * Create a new DSL DROP TABLE IF EXISTS statement.
+ *
+ * If your database doesn't natively support IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSLContext#dropTableIfExists(String)
+ */
+ @Support
public static DropTableStep dropTable(String table) {
return using(new DefaultConfiguration()).dropTable(table);
}
@@ -4371,6 +4423,19 @@ public class DSL {
return using(new DefaultConfiguration()).dropIndex(index);
}
+ /**
+ * Create a new DSL DROP INDEX IF EXISTS statement.
+ *
+ * If your database doesn't natively support
+ * If your database doesn't natively support
+ * If your database doesn't natively support
diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
index e258c206b0..28cd5c4475 100644
--- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
+++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java
@@ -1693,6 +1693,16 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return dropView(tableByName(table));
}
+ @Override
+ public DropViewFinalStep dropViewIfExists(Table> table) {
+ return new DropViewImpl(configuration, table, true);
+ }
+
+ @Override
+ public DropViewFinalStep dropViewIfExists(String table) {
+ return dropViewIfExists(tableByName(table));
+ }
+
@Override
public DropTableStep dropTable(Table> table) {
return new DropTableImpl(configuration, table);
@@ -1703,11 +1713,26 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return dropTable(tableByName(table));
}
+ @Override
+ public DropTableStep dropTableIfExists(Table> table) {
+ return new DropTableImpl(configuration, table, true);
+ }
+
+ @Override
+ public DropTableStep dropTableIfExists(String table) {
+ return dropTableIfExists(tableByName(table));
+ }
+
@Override
public DropIndexFinalStep dropIndex(String index) {
return new DropIndexImpl(configuration, index);
}
+ @Override
+ public DropIndexFinalStep dropIndexIfExists(String index) {
+ return new DropIndexImpl(configuration, index, true);
+ }
+
@Override
public DropSequenceFinalStep dropSequence(Sequence> sequence) {
return new DropSequenceImpl(configuration, sequence);
@@ -1718,6 +1743,16 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return dropSequence(sequenceByName(sequence));
}
+ @Override
+ public DropSequenceFinalStep dropSequenceIfExists(Sequence> sequence) {
+ return new DropSequenceImpl(configuration, sequence, true);
+ }
+
+ @Override
+ public DropSequenceFinalStep dropSequenceIfExists(String sequence) {
+ return dropSequenceIfExists(sequenceByName(sequence));
+ }
+
@Override
public IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSLContext#dropIndexIfExists(String)
+ */
+ @Support
+ public static DropIndexFinalStep dropIndexIfExists(String index) {
+ return using(new DefaultConfiguration()).dropIndexIfExists(index);
+ }
+
/**
* Create a new DSL DROP SEQUENCE statement.
*
@@ -4384,13 +4449,39 @@ public class DSL {
/**
* Create a new DSL DROP SEQUENCE statement.
*
- * @see DSLContext#dropSequence(Sequence)
+ * @see DSLContext#dropSequence(String)
*/
@Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
public static DROP SEQUENCE IF EXISTS statement.
+ * IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSLContext#dropSequenceIfExists(Sequence)
+ */
+ @Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
+ public static DROP SEQUENCE IF EXISTS statement.
+ * IF EXISTS, this is
+ * emulated by catching (and ignoring) the relevant {@link SQLException}.
+ *
+ * @see DSLContext#dropSequenceIfExists(String)
+ */
+ @Support({ FIREBIRD, H2, HSQLDB, POSTGRES })
+ public static DROP .. IF EXISTS statement with
+ * BEGIN EXECUTE IMMEDIATE '...' EXCEPTION WHEN ... END;, if
+ * IF EXISTS is not supported.
+ */
+ @SuppressWarnings("unused")
+ static void executeImmediateBegin(Context> ctx, DropStatementType type) {
+ switch (ctx.family()) {
+ /* [pro] xx
+ xxxx xxxx x
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxx xxxxxxxx xxxxxxx xxx xxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxx
+
+ xxxxxx
+ x
+
+ xxxx xxxxxxx x
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx xxxx
+
+ xxxxxx
+ x
+
+ xxxx xxxxxxxxxx x
+ xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxx
+ x
+
+ xx
+ xxxxxxxx xxxxxxx xxxxx xx xxxxxxxxxxx xx xxxxx
+
+ xxxxxx xxxxxxxxx xxxxxxxx
+ xx xxxxxxxxx xx xxxxx xx xxxxx xxxxxx xxxxxx xxxxx xxxxx xxxxxx xxxxx xxxxxxxxx xxxxx
+ xxx xxxxxxxxx xxxx xxxxxx
+ xxxx xxxx
+ xxx xxxxxxxxxx
+ xxxxxxx xxxxxxxxx xxxxxxxxx
+ xxxx xxxxxxxxx xxxxxxx
+ xx
+
+ xx [/pro] */
+
+ case FIREBIRD: {
+ ctx.keyword("execute block").formatSeparator()
+ .keyword("as").formatSeparator()
+ .keyword("begin").formatIndentStart().formatSeparator()
+ .keyword("execute statement").sql(" '");
+
+ break;
+ }
+
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Wrap a DROP .. IF EXISTS statement with
+ * BEGIN EXECUTE IMMEDIATE '...' EXCEPTION WHEN ... END;, if
+ * IF EXISTS is not supported.
+ */
+ static void executeImmediateEnd(Context> ctx, DropStatementType type) {
+ switch (ctx.family()) {
+ /* [pro] xx
+ xxxx xxxx x
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxx
+
+ xxxxxx
+ x
+
+ xxxx xxxxxxx x
+ xxxxxx xxx x
+ xxxx xx xxxxx x xxxxxxxxxxx
+ x xxxx xx xxxxxxxx x xxxxxxxxxxx
+ x xxxx xx xxxxx x xxxxxxxxxxx
+ x xxxx xx xxxx x xxxxxxxxxxx
+ x xxxxxxxxxxxx
+
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx xx x xxx x xxx xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxxxxxxx
+
+ xxxxxx
+ x
+
+ xxxx xxxxxxxxxx x
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xx xxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ xxxxxxxxxxxxx xxxxxxxx
+
+ xxxxxx
+ x
+
+ xx [/pro] */
+
+ case FIREBIRD: {
+ ctx.sql("';").formatSeparator()
+ .keyword("when").sql(" sqlcode -607 ").keyword("do").formatIndentStart().formatSeparator()
+ .keyword("begin end").formatIndentEnd().formatIndentEnd().formatSeparator()
+ .keyword("end");
+
+ break;
+ }
+
+ default:
+ break;
+ }
+ }
}