MCPcopy Index your code
hub / github.com/bytebase/dbhub / applyTopToQuery

Method applyTopToQuery

src/utils/sql-row-limiter.ts:92–103  ·  view source on GitHub ↗

* Add or modify TOP clause in a SQL statement (SQL Server)

(sql: string, maxRows: number)

Source from the content-addressed store, hash-verified

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).

Callers 1

Calls 1

extractTopValueMethod · 0.95

Tested by

no test coverage detected