-
Notifications
You must be signed in to change notification settings - Fork 1
/
show_procedure_status.go
123 lines (109 loc) · 4.15 KB
/
show_procedure_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2021 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package plan
import (
"github.com/Ciyfly/FakerMysql/sql"
)
type ShowProcedureStatus struct {
db sql.Database
Procedures []*Procedure
}
var _ sql.Databaser = (*ShowProcedureStatus)(nil)
var _ sql.Node = (*ShowProcedureStatus)(nil)
var showProcedureStatusSchema = sql.Schema{
&sql.Column{Name: "Db", Type: sql.LongText, Nullable: false},
&sql.Column{Name: "Name", Type: sql.LongText, Nullable: false},
&sql.Column{Name: "Type", Type: sql.LongText, Nullable: false},
&sql.Column{Name: "Definer", Type: sql.LongText, Nullable: false},
&sql.Column{Name: "Modified", Type: sql.Datetime, Nullable: false},
&sql.Column{Name: "Created", Type: sql.Datetime, Nullable: false},
&sql.Column{Name: "Security_type", Type: sql.LongText, Nullable: false},
&sql.Column{Name: "Comment", Type: sql.LongText, Nullable: false},
&sql.Column{Name: "character_set_client", Type: sql.LongText, Nullable: false},
&sql.Column{Name: "collation_connection", Type: sql.LongText, Nullable: false},
&sql.Column{Name: "Database Collation", Type: sql.LongText, Nullable: false},
}
// NewShowProcedureStatus creates a new *ShowProcedureStatus node.
func NewShowProcedureStatus(db sql.Database) *ShowProcedureStatus {
return &ShowProcedureStatus{
db: db,
}
}
// String implements the sql.Node interface.
func (s *ShowProcedureStatus) String() string {
return "SHOW PROCEDURE STATUS"
}
// Resolved implements the sql.Node interface.
func (s *ShowProcedureStatus) Resolved() bool {
_, ok := s.db.(sql.UnresolvedDatabase)
return !ok
}
// Children implements the sql.Node interface.
func (s *ShowProcedureStatus) Children() []sql.Node {
return nil
}
// Schema implements the sql.Node interface.
func (s *ShowProcedureStatus) Schema() sql.Schema {
return showProcedureStatusSchema
}
// RowIter implements the sql.Node interface.
func (s *ShowProcedureStatus) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
var rows []sql.Row
for _, procedure := range s.Procedures {
securityType := "DEFINER"
if procedure.SecurityContext == ProcedureSecurityContext_Invoker {
securityType = "INVOKER"
}
characterSetClient, err := ctx.GetSessionVariable(ctx, "character_set_client")
if err != nil {
return nil, err
}
collationConnection, err := ctx.GetSessionVariable(ctx, "collation_connection")
if err != nil {
return nil, err
}
collationServer, err := ctx.GetSessionVariable(ctx, "collation_server")
if err != nil {
return nil, err
}
rows = append(rows, sql.Row{
s.db.Name(), // Db
procedure.Name, // Name
"PROCEDURE", // Type
procedure.Definer, // Definer
procedure.ModifiedAt.UTC(), // Modified
procedure.CreatedAt.UTC(), // Created
securityType, // Security_type
procedure.Comment, // Comment
characterSetClient, // character_set_client
collationConnection, // collation_connection
collationServer, // Database Collation
})
}
return sql.RowsToRowIter(rows...), nil
}
// WithChildren implements the sql.Node interface.
func (s *ShowProcedureStatus) WithChildren(children ...sql.Node) (sql.Node, error) {
return NillaryWithChildren(s, children...)
}
// Database implements the sql.Databaser interface.
func (s *ShowProcedureStatus) Database() sql.Database {
return s.db
}
// WithDatabase implements the sql.Databaser interface.
func (s *ShowProcedureStatus) WithDatabase(db sql.Database) (sql.Node, error) {
ns := *s
ns.db = db
return &ns, nil
}