Skip to content

Commit da15274

Browse files
committed
Fix in similar fashion
1 parent f8d4eb1 commit da15274

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

sql/system_inttype.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,16 @@ func (t systemIntType) Convert(v interface{}) (interface{}, error) {
9494
return t.Convert(int64(value))
9595
case float32:
9696
return t.Convert(float64(value))
97-
case float64:
98-
// Float values aren't truly accepted, but the engine will give them when it should give ints.
99-
// Therefore, if the float doesn't have a fractional portion, we treat it as an int.
100-
if value == float64(int64(value)) {
101-
return t.Convert(int64(value))
102-
}
97+
case float64:
98+
// Float values aren't truly accepted, but the engine will give them when it should give ints.
99+
// Therefore, if the float doesn't have a fractional portion, we treat it as an int.
100+
if value == float64(int64(value)) {
101+
if value >= float64(t.lowerbound) && value <= float64(t.upperbound) {
102+
intVal := int64(value)
103+
return t.Convert(intVal)
104+
}
105+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
106+
}
103107
case decimal.Decimal:
104108
f, _ := value.Float64()
105109
return t.Convert(f)

sql/system_uinttype.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ func (t systemUintType) Convert(v interface{}) (interface{}, error) {
8888
if value >= t.lowerbound && value <= t.upperbound {
8989
return value, nil
9090
}
91-
case float32:
92-
return t.Convert(float64(value))
9391
case float64:
9492
// Float values aren't truly accepted, but the engine will give them when it should give ints.
9593
// Therefore, if the float doesn't have a fractional portion, we treat it as an int.
9694
if value == float64(uint64(value)) {
97-
return t.Convert(uint64(value))
95+
if value >= float64(t.lowerbound) && value <= float64(t.upperbound) {
96+
uintVal := uint64(value)
97+
return t.Convert(uintVal)
98+
}
99+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
98100
}
99101
case decimal.Decimal:
100102
f, _ := value.Float64()

0 commit comments

Comments
 (0)