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