Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit a514766

Browse files
committed
Changed the interface for Droppable to not consider the if exists flag
Signed-off-by: Zach Musgrave <zach@liquidata.co>
1 parent 0298181 commit a514766

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

memory/database.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ func (d *Database) Create(name string, schema sql.Schema) error {
4444
return nil
4545
}
4646

47-
func (d *Database) DropTable(name string, ifExists bool) error {
47+
func (d *Database) DropTable(name string) error {
4848
_, ok := d.tables[name]
49-
if !ok && !ifExists {
49+
if !ok {
5050
return sql.ErrTableNotFound.New(name)
5151
}
5252

sql/core.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ type Alterable interface {
237237

238238
// Droppable should be implemented by databases that can drop tables.
239239
type Droppable interface {
240-
DropTable(name string, ifExists bool) error
240+
DropTable(name string) error
241241
}
242242

243243
// Lockable should be implemented by tables that can be locked and unlocked.

sql/plan/ddl.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ func (d *DropTable) RowIter(s *sql.Context) (sql.RowIter, error) {
123123

124124
var err error
125125
for _, tableName := range d.names {
126-
err = droppable.DropTable(tableName, d.ifExists)
126+
_, ok := d.db.Tables()[tableName]
127+
if !ok {
128+
if d.ifExists {
129+
continue
130+
}
131+
return nil, sql.ErrTableNotFound.New(tableName)
132+
}
133+
err = droppable.DropTable(tableName)
127134
if err != nil {
128135
break
129136
}

sql/plan/ddl_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ func TestDropTable(t *testing.T) {
7272
d = NewDropTable(db, true, "testTable1")
7373
_, err = d.RowIter(sql.NewEmptyContext())
7474
require.NoError(err)
75+
76+
d = NewDropTable(db, true, "testTable1", "testTable2", "testTable3")
77+
_, err = d.RowIter(sql.NewEmptyContext())
78+
require.NoError(err)
79+
80+
_, ok = db.Tables()["testTable3"]
81+
require.False(ok)
7582
}
7683

7784
func createTable(t *testing.T, db sql.Database, name string, schema sql.Schema) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy