Skip to content

Commit ce87927

Browse files
committed
Exported fields in literal struct
1 parent 6d525e6 commit ce87927

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

sql/expression/div.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ func getFinalScale(ctx *sql.Context, row sql.Row, expr sql.Expression, divOpCnt
577577

578578
var fScale uint8
579579
if lit, isLit := expr.(*Literal); isLit {
580-
_, fScale = GetPrecisionAndScale(lit.value)
580+
_, fScale = GetPrecisionAndScale(lit.Val)
581581
}
582582
typ := expr.Type()
583583
if dt, dok := typ.(sql.DecimalType); dok {

sql/expression/literal.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import (
2828

2929
// Literal represents a literal expression (string, number, bool, ...).
3030
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
3434
}
3535

3636
var _ sql.Expression = &Literal{}
@@ -42,9 +42,9 @@ var _ sqlparser.Injectable = &Literal{}
4242
func 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.
5757
func (lit *Literal) IsNullable() bool {
58-
return lit.value == nil
58+
return lit.Val == nil
5959
}
6060

6161
// Type implements the Expression interface.
6262
func (lit *Literal) Type() sql.Type {
63-
return lit.fieldType
63+
return lit.Typ
6464
}
6565

6666
// CollationCoercibility implements the interface sql.CollationCoercible.
6767
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)
7070
return collation, 4
7171
}
7272
return sql.Collation_binary, 5
7373
}
7474

7575
// Eval implements the Expression interface.
7676
func (lit *Literal) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
77-
return lit.value, nil
77+
return lit.Val, nil
7878
}
7979

8080
func (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

106106
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) {
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

143143
func (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.
152152
func (p *Literal) Value() interface{} {
153-
return p.value
153+
return p.Val
154154
}
155155

156156
func (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

Comments
 (0)