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

     1  // Copyright 2023 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"
    21  	"github.com/dolthub/go-mysql-server/sql/types"
    22  )
    23  
    24  type ShowCreateEvent struct {
    25  	db    sql.Database
    26  	Event sql.EventDefinition
    27  }
    28  
    29  var _ sql.Databaser = (*ShowCreateEvent)(nil)
    30  var _ sql.Node = (*ShowCreateEvent)(nil)
    31  var _ sql.CollationCoercible = (*ShowCreateEvent)(nil)
    32  
    33  var showCreateEventSchema = sql.Schema{
    34  	&sql.Column{Name: "Event", Type: types.LongText, Nullable: false},
    35  	&sql.Column{Name: "sql_mode", Type: types.LongText, Nullable: false},
    36  	&sql.Column{Name: "time_zone", Type: types.LongText, Nullable: false},
    37  	&sql.Column{Name: "Create Event", Type: types.LongText, Nullable: false},
    38  	&sql.Column{Name: "character_set_client", Type: types.LongText, Nullable: false},
    39  	&sql.Column{Name: "collation_connection", Type: types.LongText, Nullable: false},
    40  	&sql.Column{Name: "Database Collation", Type: types.LongText, Nullable: false},
    41  }
    42  
    43  // NewShowCreateEvent creates a new ShowCreateEvent node for SHOW CREATE EVENT statements.
    44  func NewShowCreateEvent(db sql.Database, event sql.EventDefinition) *ShowCreateEvent {
    45  	return &ShowCreateEvent{
    46  		db:    db,
    47  		Event: event,
    48  	}
    49  }
    50  
    51  // String implements the sql.Node interface.
    52  func (s *ShowCreateEvent) String() string {
    53  	return fmt.Sprintf("SHOW CREATE EVENT %s", s.Event.Name)
    54  }
    55  
    56  // Resolved implements the sql.Node interface.
    57  func (s *ShowCreateEvent) Resolved() bool {
    58  	_, ok := s.db.(sql.UnresolvedDatabase)
    59  	return !ok
    60  }
    61  
    62  func (s *ShowCreateEvent) IsReadOnly() bool {
    63  	return true
    64  }
    65  
    66  // Children implements the sql.Node interface.
    67  func (s *ShowCreateEvent) Children() []sql.Node {
    68  	return nil
    69  }
    70  
    71  // Schema implements the sql.Node interface.
    72  func (s *ShowCreateEvent) Schema() sql.Schema {
    73  	return showCreateEventSchema
    74  }
    75  
    76  // WithChildren implements the sql.Node interface.
    77  func (s *ShowCreateEvent) WithChildren(children ...sql.Node) (sql.Node, error) {
    78  	return NillaryWithChildren(s, children...)
    79  }
    80  
    81  // CheckPrivileges implements the interface sql.Node.
    82  func (s *ShowCreateEvent) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool {
    83  	// TODO: figure out what privileges are needed here
    84  	return true
    85  }
    86  
    87  // CollationCoercibility implements the interface sql.CollationCoercible.
    88  func (*ShowCreateEvent) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
    89  	return sql.Collation_binary, 7
    90  }
    91  
    92  // Database implements the sql.Databaser interface.
    93  func (s *ShowCreateEvent) Database() sql.Database {
    94  	return s.db
    95  }
    96  
    97  // WithDatabase implements the sql.Databaser interface.
    98  func (s *ShowCreateEvent) WithDatabase(db sql.Database) (sql.Node, error) {
    99  	ns := *s
   100  	ns.db = db
   101  	return &ns, nil
   102  }