(sql: string)
| 72 | * tricks because `commons.sql` doesn't use them. |
| 73 | */ |
| 74 | export 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 | |
| 114 | const VARCHAR_RE = /^varchar\((\d+)\)$/i; |
| 115 | const TINYINT_RE = /^tinyint\((\d+)\)$/i; |
no test coverage detected