[#6371] Add support for DROP TEMPORARY TABLE
This commit is contained in:
parent
26850fb478
commit
8c56574e93
@ -124,7 +124,7 @@ createViewStatement = 'CREATE VIEW' [ 'IF NOT EXISTS' ] tableName
|
||||
[ '(' fieldNames ')' ] 'AS' select
|
||||
;
|
||||
|
||||
dropTableStatement = 'DROP TABLE' [ 'IF EXISTS' ] tableName [ 'CASCADE' | 'RESTRICT' ]
|
||||
dropTableStatement = 'DROP' [ 'TEMPORARY' ] 'TABLE' [ 'IF EXISTS' ] tableName [ 'CASCADE' | 'RESTRICT' ]
|
||||
;
|
||||
|
||||
dropIndexStatement = 'DROP INDEX' [ 'IF EXISTS' ] indexName [ 'ON' tableName ]
|
||||
|
||||
@ -9321,6 +9321,30 @@ public interface DSLContext extends Scope , AutoCloseable {
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
DropTableStep dropTableIfExists(Table<?> table);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
|
||||
*
|
||||
* @see DSL#dropTemporaryTable(String)
|
||||
*/
|
||||
@Support
|
||||
DropTableStep dropTemporaryTable(String table);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
|
||||
*
|
||||
* @see DSL#dropTemporaryTable(Name)
|
||||
*/
|
||||
@Support
|
||||
DropTableStep dropTemporaryTable(Name table);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
|
||||
*
|
||||
* @see DSL#dropTemporaryTable(Table)
|
||||
*/
|
||||
@Support
|
||||
DropTableStep dropTemporaryTable(Table<?> table);
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>DROP INDEX</code> statement.
|
||||
*
|
||||
|
||||
@ -7479,6 +7479,36 @@ public class DSL {
|
||||
return using(new DefaultConfiguration()).dropTable(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
|
||||
*
|
||||
* @see DSLContext#dropTemporaryTable(String)
|
||||
*/
|
||||
@Support
|
||||
public static DropTableStep dropTemporaryTable(String table) {
|
||||
return using(new DefaultConfiguration()).dropTemporaryTable(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
|
||||
*
|
||||
* @see DSLContext#dropTemporaryTable(Name)
|
||||
*/
|
||||
@Support
|
||||
public static DropTableStep dropTemporaryTable(Name table) {
|
||||
return using(new DefaultConfiguration()).dropTemporaryTable(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>DROP TEMPORARY TABLE</code> statement.
|
||||
*
|
||||
* @see DSLContext#dropTemporaryTable(Table)
|
||||
*/
|
||||
@Support
|
||||
public static DropTableStep dropTemporaryTable(Table<?> table) {
|
||||
return using(new DefaultConfiguration()).dropTemporaryTable(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSL <code>DROP TABLE IF EXISTS</code> statement.
|
||||
* <p>
|
||||
|
||||
@ -3352,6 +3352,21 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
return new DropTableImpl(configuration(), table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropTableStep dropTemporaryTable(String table) {
|
||||
return dropTable(name(table));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropTableStep dropTemporaryTable(Name table) {
|
||||
return dropTable(table(table));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropTableStep dropTemporaryTable(Table<?> table) {
|
||||
return new DropTableImpl(configuration(), table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropTableStep dropTableIfExists(String table) {
|
||||
return dropTableIfExists(name(table));
|
||||
|
||||
@ -76,18 +76,24 @@ final class DropTableImpl extends AbstractQuery implements
|
||||
private static final EnumSet<SQLDialect> NO_SUPPORT_IF_EXISTS = EnumSet.of(DERBY, FIREBIRD);
|
||||
|
||||
private final Table<?> table;
|
||||
private final boolean temporary;
|
||||
private final boolean ifExists;
|
||||
private boolean cascade;
|
||||
|
||||
DropTableImpl(Configuration configuration, Table<?> table) {
|
||||
this(configuration, table, false);
|
||||
this(configuration, table, false, false);
|
||||
}
|
||||
|
||||
DropTableImpl(Configuration configuration, Table<?> table, boolean ifExists) {
|
||||
this(configuration, table, ifExists, false);
|
||||
}
|
||||
|
||||
DropTableImpl(Configuration configuration, Table<?> table, boolean ifExists, boolean temporary) {
|
||||
super(configuration);
|
||||
|
||||
this.table = table;
|
||||
this.ifExists = ifExists;
|
||||
this.temporary = temporary;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -130,14 +136,17 @@ final class DropTableImpl extends AbstractQuery implements
|
||||
ctx.start(DROP_TABLE_TABLE)
|
||||
.visit(K_DROP_TABLE).sql(' ');
|
||||
|
||||
// [#6371] The keyword isn't strictly required in any dialect we've seen so far.
|
||||
if (temporary)
|
||||
;
|
||||
|
||||
if (ifExists && supportsIfExists(ctx))
|
||||
ctx.visit(K_IF_EXISTS).sql(' ');
|
||||
|
||||
ctx.visit(table);
|
||||
|
||||
if (cascade) {
|
||||
if (cascade)
|
||||
ctx.sql(' ').visit(K_CASCADE);
|
||||
}
|
||||
|
||||
ctx.end(DROP_TABLE_TABLE);
|
||||
}
|
||||
|
||||
@ -1271,7 +1271,9 @@ final class ParserImpl implements Parser {
|
||||
parseKeyword(ctx, "DROP");
|
||||
|
||||
if (parseKeywordIf(ctx, "TABLE"))
|
||||
return parseDropTable(ctx);
|
||||
return parseDropTable(ctx, false);
|
||||
else if (parseKeywordIf(ctx, "TEMPORARY TABLE"))
|
||||
return parseDropTable(ctx, true);
|
||||
else if (parseKeywordIf(ctx, "INDEX"))
|
||||
return parseDropIndex(ctx);
|
||||
else if (parseKeywordIf(ctx, "VIEW"))
|
||||
@ -2234,7 +2236,7 @@ final class ParserImpl implements Parser {
|
||||
return ctx.dsl.alterTable(oldName).renameTo(newName);
|
||||
}
|
||||
|
||||
private static final DDLQuery parseDropTable(ParserContext ctx) {
|
||||
private static final DDLQuery parseDropTable(ParserContext ctx, boolean temporary) {
|
||||
boolean ifExists = parseKeywordIf(ctx, "IF EXISTS");
|
||||
Table<?> tableName = parseTableName(ctx);
|
||||
boolean cascade = parseKeywordIf(ctx, "CASCADE");
|
||||
@ -2244,14 +2246,16 @@ final class ParserImpl implements Parser {
|
||||
DropTableFinalStep s2;
|
||||
|
||||
s1 = ifExists
|
||||
? ctx.dsl.dropTableIfExists(tableName)
|
||||
: ctx.dsl.dropTable(tableName);
|
||||
? ctx.dsl.dropTableIfExists(tableName)
|
||||
: temporary
|
||||
? ctx.dsl.dropTemporaryTable(tableName)
|
||||
: ctx.dsl.dropTable(tableName);
|
||||
|
||||
s2 = cascade
|
||||
? s1.cascade()
|
||||
: restrict
|
||||
? s1.restrict()
|
||||
: s1;
|
||||
? s1.cascade()
|
||||
: restrict
|
||||
? s1.restrict()
|
||||
: s1;
|
||||
|
||||
return s2;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user