* Detect column wildcards (`SELECT *` or `SELECT t.*`) anywhere in the query, * including inside subqueries. Aggregate forms like `COUNT(*)` are *not* * flagged because the parser represents those as a `star`-typed expression * argument rather than a `column_ref` with column `"*"`. * * Returns
(sql: string)
| 60 | * path. We don't want a parser hiccup to block otherwise valid queries here. |
| 61 | */ |
| 62 | function containsSelectStar(sql: string): boolean { |
| 63 | let astOrArray: AST | AST[]; |
| 64 | try { |
| 65 | astOrArray = parser.astify(sql, { database: "mysql" }); |
| 66 | } catch { |
| 67 | return false; |
| 68 | } |
| 69 | const statements = Array.isArray(astOrArray) ? astOrArray : [astOrArray]; |
| 70 | return statements.some((stmt) => nodeHasColumnStar(stmt)); |
| 71 | } |
| 72 | |
| 73 | function nodeHasColumnStar(node: unknown): boolean { |
| 74 | if (node == null || typeof node !== "object") return false; |
no test coverage detected