github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/bindvar.go (about) 1 // Copyright 2020-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 expression 16 17 import ( 18 "github.com/dolthub/go-mysql-server/sql" 19 "github.com/dolthub/go-mysql-server/sql/types" 20 ) 21 22 type BindVar struct { 23 Name string 24 Typ sql.Type 25 } 26 27 var _ sql.Expression = (*BindVar)(nil) 28 var _ sql.CollationCoercible = (*BindVar)(nil) 29 30 func NewBindVar(name string) *BindVar { 31 return &BindVar{Name: name, Typ: types.NewDeferredType(name)} 32 } 33 34 func (bv *BindVar) Resolved() bool { 35 return true 36 } 37 38 func (bv *BindVar) String() string { 39 return "BindVar(" + bv.Name + ")" 40 } 41 42 func (bv *BindVar) Type() sql.Type { 43 return bv.Typ 44 } 45 46 // CollationCoercibility implements the interface sql.CollationCoercible. 47 func (bv *BindVar) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 48 return bv.Typ.CollationCoercibility(ctx) 49 } 50 51 func (bv *BindVar) IsNullable() bool { 52 return true 53 } 54 55 func (bv *BindVar) Eval(*sql.Context, sql.Row) (interface{}, error) { 56 return nil, sql.ErrUnboundPreparedStatementVariable.New(bv.Name) 57 } 58 59 func (bv *BindVar) Children() []sql.Expression { 60 return nil 61 } 62 63 func (bv *BindVar) WithChildren(children ...sql.Expression) (sql.Expression, error) { 64 if len(children) != 0 { 65 return nil, sql.ErrInvalidChildrenNumber.New(bv, len(children), 0) 66 67 } 68 return bv, nil 69 } 70 71 func IsBindVar(e sql.Expression) bool { 72 _, ok := e.(*BindVar) 73 return ok 74 }