Skip to content

Commit c71e3ac

Browse files
author
James Cor
committed
implement drop temporary table and display temporary tables
1 parent 0e32f1d commit c71e3ac

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

sql/planbuilder/ddl.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ func (b *Builder) buildDropTable(inScope *scope, c *ast.DDL) (outScope *scope) {
253253

254254
tableScope, ok := b.buildResolvedTableForTablename(inScope, t, nil)
255255
if ok {
256+
// attempting to drop a non-temporary table with DROP TEMPORARY, results in Unknown table
257+
if _, isTmpTbl := tableScope.node.(sql.TemporaryTable); !isTmpTbl && c.Temporary {
258+
err := sql.ErrUnknownTable.New(tableName)
259+
b.handleErr(err)
260+
}
256261
dropTables = append(dropTables, tableScope.node)
257262
} else if !c.IfExists {
258263
err := sql.ErrTableNotFound.New(tableName)

sql/rowexec/show_iters.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,12 @@ func (i *showCreateTablesIter) produceCreateTableStatement(ctx *sql.Context, tab
498498
}
499499
}
500500

501-
return sql.GenerateCreateTableStatement(table.Name(), colStmts, autoInc, table.Collation().CharacterSet().Name(), table.Collation().Name(), comment), nil
501+
temp := ""
502+
if _, ok := table.(sql.TemporaryTable); ok {
503+
temp = " TEMPORARY"
504+
}
505+
506+
return sql.GenerateCreateTableStatement(table.Name(), colStmts, temp, autoInc, table.Collation().CharacterSet().Name(), table.Collation().Name(), comment), nil
502507
}
503508

504509
func produceCreateViewStatement(view *plan.SubqueryAlias) string {

sql/sqlfmt.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
// GenerateCreateTableStatement returns 'CREATE TABLE' statement with given table names
2828
// and column definition statements in order and the collation and character set names for the table
29-
func GenerateCreateTableStatement(tblName string, colStmts []string, autoInc, tblCharsetName, tblCollName, comment string) string {
29+
func GenerateCreateTableStatement(tblName string, colStmts []string, temp, autoInc, tblCharsetName, tblCollName, comment string) string {
3030
if comment != "" {
3131
// Escape any single quotes in the comment and add the COMMENT keyword
3232
comment = strings.ReplaceAll(comment, "'", "''")
@@ -38,7 +38,8 @@ func GenerateCreateTableStatement(tblName string, colStmts []string, autoInc, tb
3838
}
3939

4040
return fmt.Sprintf(
41-
"CREATE TABLE %s (\n%s\n) ENGINE=InnoDB%s DEFAULT CHARSET=%s COLLATE=%s%s",
41+
"CREATE%s TABLE %s (\n%s\n) ENGINE=InnoDB%s DEFAULT CHARSET=%s COLLATE=%s%s",
42+
temp,
4243
QuoteIdentifier(tblName),
4344
strings.Join(colStmts, ",\n"),
4445
autoInc,

0 commit comments

Comments
 (0)