spliceLimitNumber replaces the number at loc within text by min(userLimit, limitCount), where a user limit of 0 means "no limit" and becomes limitCount — the exact arithmetic of the legacy rewriter. A non-integer at loc is an error (the legacy grammar only accepted integer tokens there; anything els
(text string, loc omniast.Loc, limitCount int)
| 109 | // non-integer at loc is an error (the legacy grammar only accepted integer |
| 110 | // tokens there; anything else fell back). |
| 111 | func spliceLimitNumber(text string, loc omniast.Loc, limitCount int) (string, error) { |
| 112 | if !loc.IsValid() || loc.End > len(text) || loc.Start > loc.End { |
| 113 | return "", errors.Errorf("invalid limit number location %v", loc) |
| 114 | } |
| 115 | userLimit, err := strconv.Atoi(text[loc.Start:loc.End]) |
| 116 | if err != nil { |
| 117 | return "", errors.Wrapf(err, "non-integer limit count %q", text[loc.Start:loc.End]) |
| 118 | } |
| 119 | limit := userLimit |
| 120 | if limit == 0 || limitCount < limit { |
| 121 | limit = limitCount |
| 122 | } |
| 123 | return text[:loc.Start] + strconv.Itoa(limit) + text[loc.End:], nil |
| 124 | } |
| 125 | |
| 126 | // findRightMostSelect returns the right-most SELECT of the outermost query: |
| 127 | // for set operations the last operand's select (recursing through nested set |
no test coverage detected