Public: anyone can read this; the crew can change it.
Full suite red: test/app-dump-import.test.ts #12892
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12877-full-suite-red-test-app-dump-import-test → main 1 commit fork
1 file
changed +23
−10
src/apps/dump_import.ts +23 −10
| @@ -75,10 +75,19 @@ export interface ImportReport { | ||
| 75 | 75 | */ |
| 76 | 76 | export function splitSql(sql: string): string[] { |
| 77 | 77 | const out: string[] = []; |
| 78 | let cur = ""; | |
| 79 | let i = 0; | |
| 78 | const special = /[;'"`\-/]/g; | |
| 80 | 79 | const n = sql.length; |
| 80 | let cur = ""; | |
| 81 | let from = 0; // start of the text not yet moved into `cur` | |
| 82 | let i = 0; | |
| 83 | const flush = (end: number): void => { | |
| 84 | cur += sql.slice(from, end); | |
| 85 | }; | |
| 81 | 86 | while (i < n) { |
| 87 | special.lastIndex = i; | |
| 88 | const m = special.exec(sql); | |
| 89 | if (!m) break; | |
| 90 | i = m.index; | |
| 82 | 91 | const c = sql[i]!; |
| 83 | 92 | if (c === "'" || c === '"' || c === "`") { |
| 84 | 93 | let j = i + 1; |
| @@ -88,24 +97,28 @@ export function splitSql(sql: string): string[] { | ||
| 88 | 97 | else break; |
| 89 | 98 | } else j++; |
| 90 | 99 | } |
| 91 | cur += sql.slice(i, j + 1); | |
| 92 | i = j + 1; | |
| 100 | i = j + 1; // the quoted text stays in the pending slice | |
| 93 | 101 | } else if (c === "-" && sql[i + 1] === "-") { |
| 102 | flush(i); | |
| 94 | 103 | const end = sql.indexOf("\n", i); |
| 95 | 104 | i = end === -1 ? n : end; |
| 105 | from = i; | |
| 96 | 106 | } else if (c === "/" && sql[i + 1] === "*") { |
| 107 | flush(i); | |
| 108 | cur += " "; | |
| 97 | 109 | const end = sql.indexOf("*/", i + 2); |
| 98 | 110 | i = end === -1 ? n : end + 2; |
| 99 | cur += " "; | |
| 111 | from = i; | |
| 100 | 112 | } else if (c === ";") { |
| 101 | if (cur.trim() !== "") out.push(cur.trim()); | |
| 113 | flush(i); | |
| 114 | const t = cur.trim(); | |
| 115 | if (t !== "") out.push(t); | |
| 102 | 116 | cur = ""; |
| 103 | 117 | i++; |
| 104 | } else { | |
| 105 | cur += c; | |
| 106 | i++; | |
| 107 | } | |
| 118 | from = i; | |
| 119 | } else i++; | |
| 108 | 120 | } |
| 121 | flush(n); | |
| 109 | 122 | if (cur.trim() !== "") out.push(cur.trim()); |
| 110 | 123 | return out; |
| 111 | 124 | } |
new above
offline