MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / splitStatements

Function splitStatements

packages/wl-sdk/scripts/sql-parser.ts:74–112  ·  view source on GitHub ↗
(sql: string)

Source from the content-addressed store, hash-verified

72 * tricks because `commons.sql` doesn't use them.
73 */
74export function splitStatements(sql: string): string[] {
75 const cleaned = stripLineComments(sql);
76 const out: string[] = [];
77 let depth = 0;
78 let inSingle = false;
79 let inBacktick = false;
80 let buf = '';
81
82 for (let i = 0; i < cleaned.length; i++) {
83 const ch = cleaned[i];
84 buf += ch;
85 if (inSingle) {
86 if (ch === "'" && cleaned[i - 1] !== '\\') inSingle = false;
87 continue;
88 }
89 if (inBacktick) {
90 if (ch === '`') inBacktick = false;
91 continue;
92 }
93 if (ch === "'") {
94 inSingle = true;
95 continue;
96 }
97 if (ch === '`') {
98 inBacktick = true;
99 continue;
100 }
101 if (ch === '(') depth++;
102 else if (ch === ')') depth--;
103 else if (ch === ';' && depth === 0) {
104 const stmt = buf.slice(0, -1).trim();
105 if (stmt.length > 0) out.push(stmt);
106 buf = '';
107 }
108 }
109 const tail = buf.trim();
110 if (tail.length > 0) out.push(tail);
111 return out;
112}
113
114const VARCHAR_RE = /^varchar\((\d+)\)$/i;
115const TINYINT_RE = /^tinyint\((\d+)\)$/i;

Callers 2

sql-parser.test.tsFile · 0.90
parseSchemaFunction · 0.85

Calls 2

stripLineCommentsFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected