mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-20 14:41:31 +03:00
38 lines
632 B
Go
38 lines
632 B
Go
|
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 {
|
||
|
limit = fmt.Sprintf(" LIMIT %d", rr.Limit)
|
||
|
}
|
||
|
if rr.Offset > -1 {
|
||
|
offset = fmt.Sprintf(" OFFSET %d", rr.Offset)
|
||
|
|
||
|
if rr.Limit == -1 {
|
||
|
// MySQL requires a LIMIT if OFFSET is used. Therefore
|
||
|
// we make the LIMIT a very large number
|
||
|
limit = fmt.Sprintf(" LIMIT %d", math.MaxInt64)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sql := limit + offset
|
||
|
|
||
|
return sql, nil
|
||
|
}
|