|
|
@ -3,6 +3,7 @@ package engine |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"fmt" |
|
|
|
"math" |
|
|
|
"regexp" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
@ -189,6 +190,9 @@ func (e *SQLEngine) executeSelectStatement(ctx context.Context, stmt *sqlparser. |
|
|
|
if parseErr != nil { |
|
|
|
return &QueryResult{Error: parseErr}, parseErr |
|
|
|
} |
|
|
|
if limit64 > math.MaxInt32 || limit64 < 0 { |
|
|
|
return &QueryResult{Error: fmt.Errorf("LIMIT value %d is out of valid range", limit64)}, fmt.Errorf("LIMIT value %d is out of valid range", limit64) |
|
|
|
} |
|
|
|
limit = int(limit64) |
|
|
|
} |
|
|
|
} |
|
|
@ -314,6 +318,11 @@ func (e *SQLEngine) executeSelectWithSampleData(ctx context.Context, stmt *sqlpa |
|
|
|
if stmt.Limit != nil && stmt.Limit.Rowcount != nil { |
|
|
|
if limitExpr, ok := stmt.Limit.Rowcount.(*sqlparser.SQLVal); ok && limitExpr.Type == sqlparser.IntVal { |
|
|
|
if limit64, err := strconv.ParseInt(string(limitExpr.Val), 10, 64); err == nil { |
|
|
|
if limit64 > math.MaxInt32 || limit64 < 0 { |
|
|
|
return &QueryResult{ |
|
|
|
Error: fmt.Errorf("LIMIT value %d is out of valid range", limit64), |
|
|
|
}, fmt.Errorf("LIMIT value %d is out of valid range", limit64) |
|
|
|
} |
|
|
|
limit := int(limit64) |
|
|
|
if limit > 0 && limit < len(sampleResults) { |
|
|
|
sampleResults = sampleResults[:limit] |
|
|
@ -690,6 +699,9 @@ func (e *SQLEngine) valuesEqual(fieldValue *schema_pb.Value, compareValue interf |
|
|
|
switch v := fieldValue.Kind.(type) { |
|
|
|
case *schema_pb.Value_Int32Value: |
|
|
|
if intVal, ok := compareValue.(int64); ok { |
|
|
|
if intVal > math.MaxInt32 || intVal < math.MinInt32 { |
|
|
|
return false // Value out of range for int32, cannot be equal
|
|
|
|
} |
|
|
|
return v.Int32Value == int32(intVal) |
|
|
|
} |
|
|
|
case *schema_pb.Value_Int64Value: |
|
|
@ -708,6 +720,12 @@ func (e *SQLEngine) valueLessThan(fieldValue *schema_pb.Value, compareValue inte |
|
|
|
switch v := fieldValue.Kind.(type) { |
|
|
|
case *schema_pb.Value_Int32Value: |
|
|
|
if intVal, ok := compareValue.(int64); ok { |
|
|
|
if intVal > math.MaxInt32 { |
|
|
|
return true // int32 value is always less than values > MaxInt32
|
|
|
|
} |
|
|
|
if intVal < math.MinInt32 { |
|
|
|
return false // int32 value is always greater than values < MinInt32
|
|
|
|
} |
|
|
|
return v.Int32Value < int32(intVal) |
|
|
|
} |
|
|
|
case *schema_pb.Value_Int64Value: |
|
|
@ -722,6 +740,12 @@ func (e *SQLEngine) valueGreaterThan(fieldValue *schema_pb.Value, compareValue i |
|
|
|
switch v := fieldValue.Kind.(type) { |
|
|
|
case *schema_pb.Value_Int32Value: |
|
|
|
if intVal, ok := compareValue.(int64); ok { |
|
|
|
if intVal > math.MaxInt32 { |
|
|
|
return false // int32 value is never greater than values > MaxInt32
|
|
|
|
} |
|
|
|
if intVal < math.MinInt32 { |
|
|
|
return true // int32 value is always greater than values < MinInt32
|
|
|
|
} |
|
|
|
return v.Int32Value > int32(intVal) |
|
|
|
} |
|
|
|
case *schema_pb.Value_Int64Value: |
|
|
|