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

Function stripCommentsAndStrings

src/utils/sql-parser.ts:204–231  ·  view source on GitHub ↗
(sql: string, dialect?: ConnectorType)

Source from the content-addressed store, hash-verified

202 * When no dialect is specified, only ANSI SQL syntax is recognized.
203 */
204export function stripCommentsAndStrings(sql: string, dialect?: ConnectorType): string {
205 const scanToken = getScanner(dialect);
206 const parts: string[] = [];
207 let plainStart = -1;
208 let i = 0;
209
210 while (i < sql.length) {
211 const token = scanToken(sql, i);
212
213 if (token.type === TokenType.Plain) {
214 if (plainStart === -1) { plainStart = i; }
215 } else {
216 if (plainStart !== -1) {
217 parts.push(sql.substring(plainStart, i));
218 plainStart = -1;
219 }
220 parts.push(" ");
221 }
222
223 i = token.end;
224 }
225
226 if (plainStart !== -1) {
227 parts.push(sql.substring(plainStart));
228 }
229
230 return parts.join("");
231}
232
233/**
234 * Split SQL into individual statements, handling semicolons inside quoted contexts.

Callers 11

isReadOnlySQLFunction · 0.85
hasLimitClauseMethod · 0.85
hasTopClauseMethod · 0.85
extractLimitValueMethod · 0.85
extractTopValueMethod · 0.85
hasParameterizedLimitMethod · 0.85
detectParameterStyleFunction · 0.85
countParametersFunction · 0.85
sql-parser.test.tsFile · 0.85
executeReadOnlyMethod · 0.85
explainQueryMethod · 0.85

Calls 1

getScannerFunction · 0.85

Tested by

no test coverage detected