Skip to content

Commit ff77a7c

Browse files
author
Etienne V. Labelle
committed
fix: recognise CTE (WITH ...) queries in getQueryType
1 parent 68c2d02 commit ff77a7c

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/QueryReflection/QueryReflection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ public static function getQueryType(string $query): ?string
407407
return strtoupper($matches[1]);
408408
}
409409

410+
// WITH [RECURSIVE] cte [(col_list)] AS (subquery) [, ...] <SELECT|INSERT|UPDATE|DELETE|REPLACE>
411+
// (?1) recurses group 1 to balance parentheses inside subqueries.
412+
if (1 === preg_match('/^\s*WITH\s+(?:RECURSIVE\s+)?[`"\w]+\s*(?:\([^)]*\))?\s*AS\s*(\((?:[^()]|(?1))*\))(?:\s*,\s*[`"\w]+\s*(?:\([^)]*\))?\s*AS\s*(?1))*\s*(SELECT|INSERT|UPDATE|DELETE|REPLACE)\b/i', $query, $matches)) {
413+
return strtoupper($matches[2]);
414+
}
415+
410416
return null;
411417
}
412418

0 commit comments

Comments
 (0)