(statement string, limitCount int)
| 99 | } |
| 100 | |
| 101 | func getStatementWithResultLimitInline(statement string, limitCount int) (string, error) { |
| 102 | if strings.TrimSpace(statement) == "" { |
| 103 | return "", errors.New("empty statement") |
| 104 | } |
| 105 | |
| 106 | file, errs := parser.Parse(statement) |
| 107 | if len(errs) > 0 { |
| 108 | return "", errors.New(errs[0].Error()) |
| 109 | } |
| 110 | if file == nil || len(file.Stmts) != 1 { |
| 111 | stmtCount := 0 |
| 112 | if file != nil { |
| 113 | stmtCount = len(file.Stmts) |
| 114 | } |
| 115 | return "", errors.Errorf("expected exactly one statement, got %d", stmtCount) |
| 116 | } |
| 117 | |
| 118 | switch stmt := file.Stmts[0].(type) { |
| 119 | case *ast.SelectStmt: |
| 120 | return rewriteSelectLimit(statement, stmt, limitCount) |
| 121 | case *ast.SetOpStmt: |
| 122 | return rewriteSetOpLimit(statement, stmt, limitCount) |
| 123 | case *ast.ParenSelect: |
| 124 | switch inner := stmt.Sel.(type) { |
| 125 | case *ast.SelectStmt: |
| 126 | return rewriteSelectLimit(statement, inner, limitCount) |
| 127 | case *ast.SetOpStmt: |
| 128 | return rewriteSetOpLimit(statement, inner, limitCount) |
| 129 | } |
| 130 | return statement, nil |
| 131 | default: |
| 132 | return statement, nil |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | func hasUnparsedTail(sql string, locEnd int) bool { |
| 137 | pos := locEnd |
no test coverage detected