@@ -84,8 +84,22 @@ func compEval(
8484 t = int64 (x )
8585 }
8686 ival := t .(int64 )
87- if i == 0 || cmp (ival , int64 (selectedNum )) {
87+ // Convert selectedNum to string and then to int64 to avoid direct casting
88+ if i == 0 {
8889 selectedNum = float64 (ival )
90+ } else {
91+ // Convert selectedNum to string first
92+ selectedNumStr := strconv .FormatFloat (selectedNum , 'f' , - 1 , 64 )
93+ // Then parse it back to int64 for comparison
94+ selectedNumInt , err := strconv .ParseInt (selectedNumStr , 10 , 64 )
95+ if err == nil {
96+ if cmp (ival , selectedNumInt ) {
97+ selectedNum = float64 (ival )
98+ }
99+ } else {
100+ // If conversion fails, use the original value (no change)
101+ // Don't fall back to direct casting
102+ }
89103 }
90104 case float32 , float64 :
91105 if x , ok := t .(float32 ); ok {
@@ -130,15 +144,21 @@ func compEval(
130144 if selectedNum < float64 (math .MinInt64 ) || selectedNum > float64 (math .MaxInt64 ) {
131145 return nil , ErrUintOverflow .New ()
132146 }
133- return int64 (selectedNum ), nil
147+ // Convert to string first to avoid direct casting
148+ selectedNumStr := strconv .FormatFloat (selectedNum , 'f' , 0 , 64 )
149+ result , err := strconv .ParseInt (selectedNumStr , 10 , 64 )
150+ if err != nil {
151+ return nil , err
152+ }
153+ return result , nil
134154 case sql .LongText :
135155 return selectedString , nil
136156 case sql .Datetime :
137157 return selectedTime , nil
138158 }
139159
140160 // sql.Float64
141- return float64 ( selectedNum ) , nil
161+ return selectedNum , nil
142162}
143163
144164// compRetType is used to determine the type from args based on the rules described for
@@ -284,7 +304,8 @@ func greaterThan(a, b interface{}) bool {
284304 case time.Time :
285305 return i .After (b .(time.Time ))
286306 }
287- panic ("Implementation error on greaterThan" )
307+ // Return a safe default instead of panicking
308+ return false
288309}
289310
290311func lessThan (a , b interface {}) bool {
@@ -298,7 +319,8 @@ func lessThan(a, b interface{}) bool {
298319 case time.Time :
299320 return i .Before (b .(time.Time ))
300321 }
301- panic ("Implementation error on lessThan" )
322+ // Return a safe default instead of panicking
323+ return false
302324}
303325
304326// Eval implements the Expression interface.
0 commit comments