github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/close.go (about)

     1  // Copyright 2022 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  
    20  	"github.com/dolthub/go-mysql-server/sql/expression"
    21  
    22  	"github.com/dolthub/go-mysql-server/sql"
    23  )
    24  
    25  // Close represents the CLOSE statement, which closes a cursor.
    26  type Close struct {
    27  	Name string
    28  	Pref *expression.ProcedureReference
    29  }
    30  
    31  var _ sql.Node = (*Close)(nil)
    32  var _ sql.CollationCoercible = (*Close)(nil)
    33  var _ expression.ProcedureReferencable = (*Close)(nil)
    34  
    35  // NewClose returns a new *Close node.
    36  func NewClose(name string) *Close {
    37  	return &Close{
    38  		Name: name,
    39  	}
    40  }
    41  
    42  // Resolved implements the interface sql.Node.
    43  func (c *Close) Resolved() bool {
    44  	return true
    45  }
    46  
    47  // String implements the interface sql.Node.
    48  func (c *Close) String() string {
    49  	return fmt.Sprintf("CLOSE %s", c.Name)
    50  }
    51  
    52  // Schema implements the interface sql.Node.
    53  func (c *Close) Schema() sql.Schema {
    54  	return nil
    55  }
    56  
    57  // Children implements the interface sql.Node.
    58  func (c *Close) Children() []sql.Node {
    59  	return nil
    60  }
    61  
    62  func (c *Close) IsReadOnly() bool {
    63  	return true
    64  }
    65  
    66  // WithChildren implements the interface sql.Node.
    67  func (c *Close) WithChildren(children ...sql.Node) (sql.Node, error) {
    68  	return NillaryWithChildren(c, children...)
    69  }
    70  
    71  // CheckPrivileges implements the interface sql.Node.
    72  func (c *Close) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
    73  	return true
    74  }
    75  
    76  // CollationCoercibility implements the interface sql.CollationCoercible.
    77  func (*Close) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
    78  	return sql.Collation_binary, 7
    79  }
    80  
    81  // WithParamReference implements the interface expression.ProcedureReferencable.
    82  func (c *Close) WithParamReference(pRef *expression.ProcedureReference) sql.Node {
    83  	nc := *c
    84  	nc.Pref = pRef
    85  	return &nc
    86  }