2023-04-07 11:00:49 +03:00
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"github.com/neilotoole/sq/libsq/ast"
|
|
|
|
)
|
|
|
|
|
|
|
|
func doRange(_ *Context, rr *ast.RowRangeNode) (string, error) {
|
|
|
|
if rr == nil {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if rr.Limit < 0 && rr.Offset < 0 {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
limit := ""
|
|
|
|
offset := ""
|
|
|
|
if rr.Limit > -1 {
|
2023-07-03 18:34:19 +03:00
|
|
|
limit = fmt.Sprintf("LIMIT %d", rr.Limit)
|
2023-04-07 11:00:49 +03:00
|
|
|
}
|
|
|
|
if rr.Offset > -1 {
|
2023-07-03 18:34:19 +03:00
|
|
|
offset = fmt.Sprintf("OFFSET %d", rr.Offset)
|
2023-04-07 11:00:49 +03:00
|
|
|
|
|
|
|
if rr.Limit == -1 {
|
|
|
|
// MySQL requires a LIMIT if OFFSET is used. Therefore
|
|
|
|
// we make the LIMIT a very large number
|
2023-09-10 19:43:11 +03:00
|
|
|
limit = fmt.Sprintf("LIMIT %d", uint64(math.MaxInt64))
|
2023-04-07 11:00:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 18:34:19 +03:00
|
|
|
sql := sqlAppend(limit, offset)
|
2023-04-07 11:00:49 +03:00
|
|
|
return sql, nil
|
|
|
|
}
|