findLimitInsertPosition returns the byte offset where " LIMIT N" should be inserted, and whether the insertion is before a locking clause (FOR UPDATE/SHARE).
(sel *ast.SelectStmt)
| 280 | // findLimitInsertPosition returns the byte offset where " LIMIT N" should be inserted, |
| 281 | // and whether the insertion is before a locking clause (FOR UPDATE/SHARE). |
| 282 | func findLimitInsertPosition(sel *ast.SelectStmt) (int, bool) { |
| 283 | // LIMIT must appear before FOR UPDATE/SHARE. |
| 284 | if sel.LockingClause != nil { |
| 285 | span := ast.ListSpan(sel.LockingClause) |
| 286 | if span.Start > 0 { |
| 287 | return span.Start, true |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | // Otherwise insert at SelectStmt.Loc.End (after everything, including outer parens). |
| 292 | // For CTE queries, omni may report SelectStmt.Loc.End before the outer ORDER BY, |
| 293 | // so account for the sort clause explicitly. |
| 294 | end := sel.Loc.End |
| 295 | if span := ast.ListSpan(sel.SortClause); span.End > end { |
| 296 | end = span.End |
| 297 | } |
| 298 | if end <= 0 { |
| 299 | return 0, false |
| 300 | } |
| 301 | return end, false |
| 302 | } |
| 303 | |
| 304 | // extractIntFromNode extracts an integer value from a LIMIT/OFFSET node. |
| 305 | func extractIntFromNode(node ast.Node) int { |
no outgoing calls
no test coverage detected