github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/showdatabases.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 plan 16 17 import ( 18 "github.com/dolthub/go-mysql-server/sql" 19 "github.com/dolthub/go-mysql-server/sql/types" 20 ) 21 22 // ShowDatabases is a node that shows the databases. 23 type ShowDatabases struct { 24 Catalog sql.Catalog 25 } 26 27 var _ sql.Node = (*ShowDatabases)(nil) 28 var _ sql.CollationCoercible = (*ShowDatabases)(nil) 29 30 // NewShowDatabases creates a new show databases node. 31 func NewShowDatabases() *ShowDatabases { 32 return new(ShowDatabases) 33 } 34 35 // Resolved implements the Resolvable interface. 36 func (p *ShowDatabases) Resolved() bool { 37 return true 38 } 39 40 // Children implements the Node interface. 41 func (*ShowDatabases) Children() []sql.Node { 42 return nil 43 } 44 45 func (*ShowDatabases) IsReadOnly() bool { 46 return true 47 } 48 49 // Schema implements the Node interface. 50 func (*ShowDatabases) Schema() sql.Schema { 51 return sql.Schema{{ 52 Name: "Database", 53 Type: types.LongText, 54 Nullable: false, 55 }} 56 } 57 58 // WithChildren implements the Node interface. 59 func (p *ShowDatabases) WithChildren(children ...sql.Node) (sql.Node, error) { 60 if len(children) != 0 { 61 return nil, sql.ErrInvalidChildrenNumber.New(p, len(children), 0) 62 } 63 64 return p, nil 65 } 66 67 // CheckPrivileges implements the interface sql.Node. 68 func (p *ShowDatabases) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { 69 //TODO: Having the "SHOW DATABASES" privilege should allow one to see all databases 70 // Currently, only shows databases that the user has access to 71 return true 72 } 73 74 // CollationCoercibility implements the interface sql.CollationCoercible. 75 func (*ShowDatabases) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 76 return sql.Collation_binary, 7 77 } 78 79 func (p ShowDatabases) String() string { 80 return "ShowDatabases" 81 }