github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/declare_condition.go (about) 1 // Copyright 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 "fmt" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 ) 22 23 // DeclareCondition represents the DECLARE ... CONDITION statement. 24 type DeclareCondition struct { 25 Name string 26 MysqlErrCode int64 27 SqlStateValue string 28 } 29 30 var _ sql.Node = (*DeclareCondition)(nil) 31 var _ sql.CollationCoercible = (*DeclareCondition)(nil) 32 33 // NewDeclareCondition returns a *DeclareCondition node. 34 func NewDeclareCondition(name string, errCode int64, sqlStateValue string) *DeclareCondition { 35 return &DeclareCondition{ 36 Name: name, 37 MysqlErrCode: errCode, 38 SqlStateValue: sqlStateValue, 39 } 40 } 41 42 // Resolved implements the sql.Node interface. 43 func (d *DeclareCondition) Resolved() bool { 44 return true 45 } 46 47 func (d *DeclareCondition) IsReadOnly() bool { 48 return true 49 } 50 51 // String implements the sql.Node interface. 52 func (d *DeclareCondition) String() string { 53 val := "" 54 if d.SqlStateValue != "" { 55 val = fmt.Sprintf("SQLSTATE '%s'", d.SqlStateValue) 56 } else { 57 val = fmt.Sprintf("%d", d.MysqlErrCode) 58 } 59 return fmt.Sprintf("DECLARE %s CONDITION FOR %s", d.Name, val) 60 } 61 62 // Schema implements the sql.Node interface. 63 func (d *DeclareCondition) Schema() sql.Schema { 64 return nil 65 } 66 67 // Children implements the sql.Node interface. 68 func (d *DeclareCondition) Children() []sql.Node { 69 return nil 70 } 71 72 // WithChildren implements the sql.Node interface. 73 func (d *DeclareCondition) WithChildren(children ...sql.Node) (sql.Node, error) { 74 return NillaryWithChildren(d, children...) 75 } 76 77 // CheckPrivileges implements the interface sql.Node. 78 func (d *DeclareCondition) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { 79 return true 80 } 81 82 // CollationCoercibility implements the interface sql.CollationCoercible. 83 func (*DeclareCondition) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 84 return sql.Collation_binary, 7 85 } 86 87 // RowIter implements the sql.Node interface. 88 func (d *DeclareCondition) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) { 89 return sql.RowsToRowIter(), nil 90 }