github.com/dolthub/go-mysql-server@v0.18.0/sql/analyzer/resolve_tables.go (about) 1 // Copyright 2020-2021 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package analyzer 16 17 import ( 18 "github.com/dolthub/vitess/go/mysql" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 "github.com/dolthub/go-mysql-server/sql/plan" 22 "github.com/dolthub/go-mysql-server/sql/transform" 23 ) 24 25 // validateDropTables ensures that each TableNode in DropTable is droppable, any UnresolvedTables are 26 // skipped due to `IF EXISTS` clause, and there aren't any non-table nodes. 27 func validateDropTables(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector) (sql.Node, transform.TreeIdentity, error) { 28 dt, ok := n.(*plan.DropTable) 29 if !ok { 30 return n, transform.SameTree, nil 31 } 32 33 for _, table := range dt.Tables { 34 switch t := table.(type) { 35 case *plan.ResolvedTable: 36 if _, ok := t.SqlDatabase.(sql.TableDropper); !ok { 37 return nil, transform.SameTree, sql.ErrDropTableNotSupported.New(t.Database().Name()) 38 } 39 case *plan.UnresolvedTable: 40 if dt.IfExists() && ctx != nil && ctx.Session != nil { 41 ctx.Session.Warn(&sql.Warning{ 42 Level: "Note", 43 Code: mysql.ERBadTable, 44 Message: sql.ErrUnknownTable.New(t.Name()).Error(), 45 }) 46 continue 47 } 48 return nil, transform.SameTree, sql.ErrUnknownTable.New(t.Name()) 49 default: 50 return nil, transform.SameTree, sql.ErrUnknownTable.New(getTableName(table)) 51 } 52 } 53 54 return n, transform.SameTree, nil 55 }