@@ -19,6 +19,7 @@ import (
19
19
"strings"
20
20
21
21
"github.com/dolthub/vitess/go/vt/proto/query"
22
+ "github.com/dolthub/vitess/go/vt/sqlparser"
22
23
"github.com/shopspring/decimal"
23
24
24
25
"github.com/dolthub/go-mysql-server/sql"
@@ -27,22 +28,23 @@ import (
27
28
28
29
// Literal represents a literal expression (string, number, bool, ...).
29
30
type Literal struct {
30
- value interface {}
31
- val2 sql.Value
32
- fieldType sql.Type
31
+ Val interface {}
32
+ Typ sql.Type
33
+ val2 sql.Value
33
34
}
34
35
35
36
var _ sql.Expression = & Literal {}
36
37
var _ sql.Expression2 = & Literal {}
37
38
var _ sql.CollationCoercible = & Literal {}
39
+ var _ sqlparser.Injectable = & Literal {}
38
40
39
41
// NewLiteral creates a new Literal expression.
40
42
func NewLiteral (value interface {}, fieldType sql.Type ) * Literal {
41
43
val2 , _ := sql .ConvertToValue (value )
42
44
return & Literal {
43
- value : value ,
44
- val2 : val2 ,
45
- fieldType : fieldType ,
45
+ Val : value ,
46
+ val2 : val2 ,
47
+ Typ : fieldType ,
46
48
}
47
49
}
48
50
@@ -53,34 +55,34 @@ func (lit *Literal) Resolved() bool {
53
55
54
56
// IsNullable implements the Expression interface.
55
57
func (lit * Literal ) IsNullable () bool {
56
- return lit .value == nil
58
+ return lit .Val == nil
57
59
}
58
60
59
61
// Type implements the Expression interface.
60
62
func (lit * Literal ) Type () sql.Type {
61
- return lit .fieldType
63
+ return lit .Typ
62
64
}
63
65
64
66
// CollationCoercibility implements the interface sql.CollationCoercible.
65
67
func (lit * Literal ) CollationCoercibility (ctx * sql.Context ) (collation sql.CollationID , coercibility byte ) {
66
- if types .IsText (lit .fieldType ) {
67
- collation , _ = lit .fieldType .CollationCoercibility (ctx )
68
+ if types .IsText (lit .Typ ) {
69
+ collation , _ = lit .Typ .CollationCoercibility (ctx )
68
70
return collation , 4
69
71
}
70
72
return sql .Collation_binary , 5
71
73
}
72
74
73
75
// Eval implements the Expression interface.
74
76
func (lit * Literal ) Eval (ctx * sql.Context , row sql.Row ) (interface {}, error ) {
75
- return lit .value , nil
77
+ return lit .Val , nil
76
78
}
77
79
78
80
func (lit * Literal ) String () string {
79
- switch litVal := lit .value .(type ) {
81
+ switch litVal := lit .Val .(type ) {
80
82
case int , int8 , int16 , int32 , int64 , uint , uint8 , uint16 , uint32 , uint64 :
81
83
return fmt .Sprintf ("%d" , litVal )
82
84
case string :
83
- switch lit .fieldType .Type () {
85
+ switch lit .Typ .Type () {
84
86
// utf8 charset cannot encode binary string
85
87
case query .Type_VARBINARY , query .Type_BINARY :
86
88
return fmt .Sprintf ("'0x%X'" , litVal )
@@ -102,8 +104,8 @@ func (lit *Literal) String() string {
102
104
}
103
105
104
106
func (lit * Literal ) DebugString () string {
105
- typeStr := lit .fieldType .String ()
106
- switch v := lit .value .(type ) {
107
+ typeStr := lit .Typ .String ()
108
+ switch v := lit .Val .(type ) {
107
109
case string :
108
110
return fmt .Sprintf ("%s (%s)" , v , typeStr )
109
111
case []byte :
@@ -139,14 +141,21 @@ func (lit *Literal) Eval2(ctx *sql.Context, row sql.Row2) (sql.Value, error) {
139
141
}
140
142
141
143
func (lit * Literal ) Type2 () sql.Type2 {
142
- t2 , ok := lit .fieldType .(sql.Type2 )
144
+ t2 , ok := lit .Typ .(sql.Type2 )
143
145
if ! ok {
144
- panic (fmt .Errorf ("expected Type2, but was %T" , lit .fieldType ))
146
+ panic (fmt .Errorf ("expected Type2, but was %T" , lit .Typ ))
145
147
}
146
148
return t2
147
149
}
148
150
149
151
// Value returns the literal value.
150
152
func (p * Literal ) Value () interface {} {
151
- return p .value
153
+ return p .Val
154
+ }
155
+
156
+ func (lit * Literal ) WithResolvedChildren (children []any ) (any , error ) {
157
+ if len (children ) != 0 {
158
+ return nil , sql .ErrInvalidChildrenNumber .New (lit , len (children ), 0 )
159
+ }
160
+ return lit , nil
152
161
}
0 commit comments