github.com/matrixorigin/matrixone@v0.7.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  type Prepare interface {
    18  	Statement
    19  }
    20  
    21  type prepareImpl struct {
    22  	Prepare
    23  	Format string
    24  }
    25  
    26  type PrepareStmt struct {
    27  	prepareImpl
    28  	Name Identifier
    29  	Stmt Statement
    30  }
    31  
    32  type PrepareString struct {
    33  	prepareImpl
    34  	Name Identifier
    35  	Sql  string
    36  }
    37  
    38  func (node *PrepareStmt) Format(ctx *FmtCtx) {
    39  	ctx.WriteString("prepare ")
    40  	node.Name.Format(ctx)
    41  	ctx.WriteString(" from ")
    42  	node.Stmt.Format(ctx)
    43  }
    44  
    45  func (node *PrepareString) Format(ctx *FmtCtx) {
    46  	ctx.WriteString("prepare ")
    47  	node.Name.Format(ctx)
    48  	ctx.WriteString(" from ")
    49  	ctx.WriteString(node.Sql)
    50  }
    51  
    52  func (node *PrepareStmt) GetStatementType() string   { return "Prepare" }
    53  func (node *PrepareStmt) GetQueryType() string       { return QueryTypeOth }
    54  func (node *PrepareString) GetStatementType() string { return "Prepare" }
    55  func (node *PrepareString) GetQueryType() string     { return QueryTypeOth }
    56  
    57  func NewPrepareStmt(name Identifier, statement Statement) *PrepareStmt {
    58  	return &PrepareStmt{
    59  		Name: name,
    60  		Stmt: statement,
    61  	}
    62  }
    63  
    64  func NewPrepareString(name Identifier, sql string) *PrepareString {
    65  	return &PrepareString{
    66  		Name: name,
    67  		Sql:  sql,
    68  	}
    69  }