github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/set.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 "fmt" 19 "strings" 20 21 "github.com/dolthub/go-mysql-server/sql" 22 ) 23 24 // Set represents a set statement. This can be variables, but in some instances can also refer to row values. 25 type Set struct { 26 Exprs []sql.Expression 27 } 28 29 var _ sql.Node = (*Set)(nil) 30 var _ sql.CollationCoercible = (*Set)(nil) 31 32 // NewSet creates a new Set node. 33 func NewSet(vars []sql.Expression) *Set { 34 return &Set{Exprs: vars} 35 } 36 37 // Resolved implements the sql.Node interface. 38 func (s *Set) Resolved() bool { 39 for _, v := range s.Exprs { 40 if !v.Resolved() { 41 return false 42 } 43 } 44 return true 45 } 46 47 // Children implements the sql.Node interface. 48 func (s *Set) Children() []sql.Node { return nil } 49 50 func (s *Set) IsReadOnly() bool { return true } 51 52 // WithChildren implements the sql.Node interface. 53 func (s *Set) WithChildren(children ...sql.Node) (sql.Node, error) { 54 if len(children) != 0 { 55 return nil, sql.ErrInvalidChildrenNumber.New(s, len(children), 0) 56 } 57 58 return s, nil 59 } 60 61 // CheckPrivileges implements the interface sql.Node. 62 func (s *Set) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { 63 //TODO: determine which variables cannot be set without a privilege check 64 return true 65 } 66 67 // CollationCoercibility implements the interface sql.CollationCoercible. 68 func (*Set) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 69 return sql.Collation_binary, 7 70 } 71 72 // WithExpressions implements the sql.Expressioner interface. 73 func (s *Set) WithExpressions(exprs ...sql.Expression) (sql.Node, error) { 74 if len(exprs) != len(s.Exprs) { 75 return nil, sql.ErrInvalidChildrenNumber.New(s, len(exprs), len(s.Exprs)) 76 } 77 78 return NewSet(exprs), nil 79 } 80 81 // Expressions implements the sql.Expressioner interface. 82 func (s *Set) Expressions() []sql.Expression { 83 return s.Exprs 84 } 85 86 // Schema implements the sql.Node interface. 87 func (s *Set) Schema() sql.Schema { 88 return nil 89 } 90 91 func (s *Set) String() string { 92 var children = make([]string, len(s.Exprs)) 93 for i, v := range s.Exprs { 94 children[i] = fmt.Sprintf(v.String()) 95 } 96 return strings.Join(children, ", ") 97 } 98 99 func (s *Set) DebugString() string { 100 var children = make([]string, len(s.Exprs)) 101 for i, v := range s.Exprs { 102 children[i] = fmt.Sprintf(sql.DebugString(v)) 103 } 104 return strings.Join(children, ", ") 105 }