github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/begin_end_block.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/expression" 20 ) 21 22 // BeginEndBlock represents a BEGIN/END block. 23 type BeginEndBlock struct { 24 *Block 25 Label string 26 Pref *expression.ProcedureReference 27 } 28 29 // NewBeginEndBlock creates a new *BeginEndBlock node. 30 func NewBeginEndBlock(label string, block *Block) *BeginEndBlock { 31 return &BeginEndBlock{ 32 Block: block, 33 Label: label, 34 } 35 } 36 37 var _ sql.Node = (*BeginEndBlock)(nil) 38 var _ sql.CollationCoercible = (*BeginEndBlock)(nil) 39 var _ sql.DebugStringer = (*BeginEndBlock)(nil) 40 var _ expression.ProcedureReferencable = (*BeginEndBlock)(nil) 41 var _ RepresentsLabeledBlock = (*BeginEndBlock)(nil) 42 var _ RepresentsScope = (*BeginEndBlock)(nil) 43 44 // String implements the interface sql.Node. 45 func (b *BeginEndBlock) String() string { 46 label := "" 47 if len(b.Label) > 0 { 48 label = b.Label + ": " 49 } 50 p := sql.NewTreePrinter() 51 _ = p.WriteNode(label + "BEGIN .. END") 52 var children []string 53 for _, s := range b.statements { 54 children = append(children, s.String()) 55 } 56 _ = p.WriteChildren(children...) 57 return p.String() 58 } 59 60 // DebugString implements the interface sql.DebugStringer. 61 func (b *BeginEndBlock) DebugString() string { 62 label := "" 63 if len(b.Label) > 0 { 64 label = b.Label + ": " 65 } 66 p := sql.NewTreePrinter() 67 _ = p.WriteNode(label + "BEGIN .. END") 68 var children []string 69 for _, s := range b.statements { 70 children = append(children, sql.DebugString(s)) 71 } 72 _ = p.WriteChildren(children...) 73 return p.String() 74 } 75 76 // WithChildren implements the interface sql.Node. 77 func (b *BeginEndBlock) WithChildren(children ...sql.Node) (sql.Node, error) { 78 newBeginEndBlock := *b 79 newBlock := *b.Block 80 newBlock.statements = children 81 newBeginEndBlock.Block = &newBlock 82 return &newBeginEndBlock, nil 83 } 84 85 // CheckPrivileges implements the interface sql.Node. 86 func (b *BeginEndBlock) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { 87 return b.Block.CheckPrivileges(ctx, opChecker) 88 } 89 90 // CollationCoercibility implements the interface sql.CollationCoercible. 91 func (b *BeginEndBlock) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 92 return b.Block.CollationCoercibility(ctx) 93 } 94 95 // WithParamReference implements the interface expression.ProcedureReferencable. 96 func (b *BeginEndBlock) WithParamReference(pRef *expression.ProcedureReference) sql.Node { 97 nb := *b 98 nb.Pref = pRef 99 return &nb 100 } 101 102 // implementsRepresentsScope implements the interface RepresentsScope. 103 func (b *BeginEndBlock) implementsRepresentsScope() {} 104 105 // GetBlockLabel implements the interface RepresentsLabeledBlock. 106 func (b *BeginEndBlock) GetBlockLabel(ctx *sql.Context) string { 107 return b.Label 108 } 109 110 // RepresentsLoop implements the interface RepresentsLabeledBlock. 111 func (b *BeginEndBlock) RepresentsLoop() bool { 112 return false 113 }