MCPcopy Create free account
hub / github.com/bytebase/dbhub / splitSQLStatements

Function splitSQLStatements

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

Source from the content-addressed store, hash-verified

235 * When no dialect is specified, only ANSI SQL syntax is recognized.
236 */
237export function splitSQLStatements(sql: string, dialect?: ConnectorType): string[] {
238 const scanToken = getScanner(dialect);
239 const statements: string[] = [];
240 let stmtStart = 0;
241 let i = 0;
242
243 while (i < sql.length) {
244 if (sql[i] === ";") {
245 const trimmed = sql.substring(stmtStart, i).trim();
246 if (trimmed.length > 0) { statements.push(trimmed); }
247 stmtStart = i + 1;
248 i++;
249 continue;
250 }
251
252 const token = scanToken(sql, i);
253 i = token.end;
254 }
255
256 const trimmed = sql.substring(stmtStart).trim();
257 if (trimmed.length > 0) { statements.push(trimmed); }
258
259 return statements;
260}

Callers 8

areAllStatementsReadOnlyFunction · 0.85
areAllStatementsReadOnlyFunction · 0.85
sql-parser.test.tsFile · 0.85
executeSQLMethod · 0.85
executeSQLMethod · 0.85
executeSQLMethod · 0.85
executeSQLMethod · 0.85

Calls 1

getScannerFunction · 0.85

Tested by 1

areAllStatementsReadOnlyFunction · 0.68