github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/rename_user.go (about) 1 // Copyright 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 "github.com/dolthub/go-mysql-server/sql/types" 23 ) 24 25 // RenameUser represents the statement RENAME USER. 26 type RenameUser struct { 27 OldName []UserName 28 NewName []UserName 29 } 30 31 var _ sql.Node = (*RenameUser)(nil) 32 var _ sql.CollationCoercible = (*RenameUser)(nil) 33 34 // NewRenameUser returns a new RenameUser node. 35 func NewRenameUser(oldNames []UserName, newNames []UserName) *RenameUser { 36 return &RenameUser{ 37 OldName: oldNames, 38 NewName: newNames, 39 } 40 } 41 42 // Schema implements the interface sql.Node. 43 func (n *RenameUser) Schema() sql.Schema { 44 return types.OkResultSchema 45 } 46 47 func (n *RenameUser) IsReadOnly() bool { 48 return false 49 } 50 51 // String implements the interface sql.Node. 52 func (n *RenameUser) String() string { 53 strs := make([]string, len(n.OldName)) 54 for i := range n.OldName { 55 strs[i] = fmt.Sprintf("%s->%s", 56 n.OldName[i].String(""), n.NewName[i].String("")) 57 } 58 return fmt.Sprintf("RenameUser(%s)", strings.Join(strs, ", ")) 59 } 60 61 // Resolved implements the interface sql.Node. 62 func (n *RenameUser) Resolved() bool { 63 return true 64 } 65 66 // Children implements the interface sql.Node. 67 func (n *RenameUser) Children() []sql.Node { 68 return nil 69 } 70 71 // WithChildren implements the interface sql.Node. 72 func (n *RenameUser) WithChildren(children ...sql.Node) (sql.Node, error) { 73 if len(children) != 0 { 74 return nil, sql.ErrInvalidChildrenNumber.New(n, len(children), 0) 75 } 76 return n, nil 77 } 78 79 // CheckPrivileges implements the interface sql.Node. 80 func (n *RenameUser) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { 81 return opChecker.UserHasPrivileges(ctx, sql.NewPrivilegedOperation(sql.PrivilegeCheckSubject{}, sql.PrivilegeType_CreateUser)) 82 } 83 84 // CollationCoercibility implements the interface sql.CollationCoercible. 85 func (*RenameUser) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 86 return sql.Collation_binary, 7 87 } 88 89 // RowIter implements the interface sql.Node. 90 func (n *RenameUser) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) { 91 return nil, fmt.Errorf("not yet implemented") 92 }