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