github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/prepare.go (about) 1 // Copyright 2021 - 2022 Matrix Origin 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 tree 16 17 import "github.com/matrixorigin/matrixone/pkg/common/reuse" 18 19 func init() { 20 reuse.CreatePool[PrepareStmt]( 21 func() *PrepareStmt { return &PrepareStmt{} }, 22 func(p *PrepareStmt) { p.reset() }, 23 reuse.DefaultOptions[PrepareStmt](), //. 24 ) //WithEnableChecker() 25 26 reuse.CreatePool[PrepareString]( 27 func() *PrepareString { return &PrepareString{} }, 28 func(p *PrepareString) { p.reset() }, 29 reuse.DefaultOptions[PrepareString](), //. 30 ) //WithEnableChecker() 31 } 32 33 type Prepare interface { 34 Statement 35 } 36 37 type prepareImpl struct { 38 Prepare 39 Format string 40 } 41 42 func (node *prepareImpl) Free() { 43 } 44 45 type PrepareStmt struct { 46 prepareImpl 47 Name Identifier 48 Stmt Statement 49 } 50 51 func (node *PrepareStmt) Format(ctx *FmtCtx) { 52 ctx.WriteString("prepare ") 53 node.Name.Format(ctx) 54 ctx.WriteString(" from ") 55 node.Stmt.Format(ctx) 56 } 57 58 func (node *PrepareStmt) GetStatementType() string { return "Prepare" } 59 func (node *PrepareStmt) GetQueryType() string { return QueryTypeOth } 60 61 func (node *PrepareStmt) Free() { 62 reuse.Free[PrepareStmt](node, nil) 63 } 64 65 func (node *PrepareStmt) reset() { 66 *node = PrepareStmt{} 67 } 68 69 func (node PrepareStmt) TypeName() string { return "tree.PrepareStmt" } 70 71 type PrepareString struct { 72 prepareImpl 73 Name Identifier 74 Sql string 75 } 76 77 func (node *PrepareString) Format(ctx *FmtCtx) { 78 ctx.WriteString("prepare ") 79 node.Name.Format(ctx) 80 ctx.WriteString(" from ") 81 ctx.WriteString(node.Sql) 82 } 83 84 func (node *PrepareString) GetStatementType() string { return "Prepare" } 85 func (node *PrepareString) GetQueryType() string { return QueryTypeOth } 86 87 func (node *PrepareString) Free() { 88 reuse.Free[PrepareString](node, nil) 89 } 90 91 func (node *PrepareString) reset() { 92 *node = PrepareString{} 93 } 94 95 func (node PrepareString) TypeName() string { return "tree.PrepareString" } 96 97 func NewPrepareStmt(name Identifier, statement Statement) *PrepareStmt { 98 preparestmt := reuse.Alloc[PrepareStmt](nil) 99 preparestmt.Name = name 100 preparestmt.Stmt = statement 101 return preparestmt 102 } 103 104 func NewPrepareString(name Identifier, sql string) *PrepareString { 105 preparestmt := reuse.Alloc[PrepareString](nil) 106 preparestmt.Name = name 107 preparestmt.Sql = sql 108 return preparestmt 109 }