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

Method extractTopValue

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

* Extract existing TOP value from SQL if present (SQL Server). * Strips comments and string literals first to avoid false positives.

(sql: string)

Source from the content-addressed store, hash-verified

56 * Strips comments and string literals first to avoid false positives.
57 */
58 static extractTopValue(sql: string): number | null {
59 // Strip comments and strings to avoid matching TOP inside them
60 const cleanedSQL = stripCommentsAndStrings(sql);
61 const topMatch = cleanedSQL.match(/\bselect\s+top\s+(\d+)/i);
62 if (topMatch) {
63 return parseInt(topMatch[1], 10);
64 }
65 return null;
66 }
67
68 /**
69 * Add or modify LIMIT clause in a SQL statement

Callers 1

applyTopToQueryMethod · 0.95

Calls 1

stripCommentsAndStringsFunction · 0.85

Tested by

no test coverage detected