@@ -28,9 +28,9 @@ import (
2828
2929// Literal represents a literal expression (string, number, bool, ...).
3030type Literal struct {
31- value interface {}
32- val2 sql.Value
33- fieldType sql.Type
31+ Val interface {}
32+ Typ sql.Type
33+ val2 sql.Value
3434}
3535
3636var _ sql.Expression = & Literal {}
@@ -42,9 +42,9 @@ var _ sqlparser.Injectable = &Literal{}
4242func NewLiteral (value interface {}, fieldType sql.Type ) * Literal {
4343 val2 , _ := sql .ConvertToValue (value )
4444 return & Literal {
45- value : value ,
46- val2 : val2 ,
47- fieldType : fieldType ,
45+ Val : value ,
46+ val2 : val2 ,
47+ Typ : fieldType ,
4848 }
4949}
5050
@@ -55,34 +55,34 @@ func (lit *Literal) Resolved() bool {
5555
5656// IsNullable implements the Expression interface.
5757func (lit * Literal ) IsNullable () bool {
58- return lit .value == nil
58+ return lit .Val == nil
5959}
6060
6161// Type implements the Expression interface.
6262func (lit * Literal ) Type () sql.Type {
63- return lit .fieldType
63+ return lit .Typ
6464}
6565
6666// CollationCoercibility implements the interface sql.CollationCoercible.
6767func (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 )
7070 return collation , 4
7171 }
7272 return sql .Collation_binary , 5
7373}
7474
7575// Eval implements the Expression interface.
7676func (lit * Literal ) Eval (ctx * sql.Context , row sql.Row ) (interface {}, error ) {
77- return lit .value , nil
77+ return lit .Val , nil
7878}
7979
8080func (lit * Literal ) String () string {
81- switch litVal := lit .value .(type ) {
81+ switch litVal := lit .Val .(type ) {
8282 case int , int8 , int16 , int32 , int64 , uint , uint8 , uint16 , uint32 , uint64 :
8383 return fmt .Sprintf ("%d" , litVal )
8484 case string :
85- switch lit .fieldType .Type () {
85+ switch lit .Typ .Type () {
8686 // utf8 charset cannot encode binary string
8787 case query .Type_VARBINARY , query .Type_BINARY :
8888 return fmt .Sprintf ("'0x%X'" , litVal )
@@ -104,8 +104,8 @@ func (lit *Literal) String() string {
104104}
105105
106106func (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 ) {
109109 case string :
110110 return fmt .Sprintf ("%s (%s)" , v , typeStr )
111111 case []byte :
@@ -141,21 +141,21 @@ func (lit *Literal) Eval2(ctx *sql.Context, row sql.Row2) (sql.Value, error) {
141141}
142142
143143func (lit * Literal ) Type2 () sql.Type2 {
144- t2 , ok := lit .fieldType .(sql.Type2 )
144+ t2 , ok := lit .Typ .(sql.Type2 )
145145 if ! ok {
146- panic (fmt .Errorf ("expected Type2, but was %T" , lit .fieldType ))
146+ panic (fmt .Errorf ("expected Type2, but was %T" , lit .Typ ))
147147 }
148148 return t2
149149}
150150
151151// Value returns the literal value.
152152func (p * Literal ) Value () interface {} {
153- return p .value
153+ return p .Val
154154}
155155
156156func (lit * Literal ) WithResolvedChildren (children []any ) (any , error ) {
157157 if len (children ) != 0 {
158158 return nil , sql .ErrInvalidChildrenNumber .New (lit , len (children ), 0 )
159159 }
160160 return lit , nil
161- }
161+ }
0 commit comments