(sql: string, dialect?: ConnectorType)
| 202 | * When no dialect is specified, only ANSI SQL syntax is recognized. |
| 203 | */ |
| 204 | export 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. |
no test coverage detected