* Add or modify TOP clause in a SQL statement (SQL Server)
(sql: string, maxRows: number)
| 90 | * Add or modify TOP clause in a SQL statement (SQL Server) |
| 91 | */ |
| 92 | static applyTopToQuery(sql: string, maxRows: number): string { |
| 93 | const existingTop = this.extractTopValue(sql); |
| 94 | |
| 95 | if (existingTop !== null) { |
| 96 | // Use the minimum of existing top and maxRows |
| 97 | const effectiveTop = Math.min(existingTop, maxRows); |
| 98 | return sql.replace(/\bselect\s+top\s+\d+/i, `SELECT TOP ${effectiveTop}`); |
| 99 | } else { |
| 100 | // Add TOP clause after SELECT |
| 101 | return sql.replace(/\bselect\s+/i, `SELECT TOP ${maxRows} `); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Check if a LIMIT clause uses a parameter placeholder (not a literal number). |
no test coverage detected