@@ -508,9 +508,8 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey): Fore
508
508
509
509
private function parseColumnCollationFromSQL (string $ column , string $ sql ): ?string
510
510
{
511
- $ pattern = '{(?:\W ' . preg_quote ($ column ) . '\W|\W '
512
- . preg_quote ($ this ->_platform ->quoteSingleIdentifier ($ column ))
513
- . '\W)[^,(]+(?:\([^()]+\)[^,]*)?(?:(?:DEFAULT|CHECK)\s*(?:\(.*?\))?[^,]*)*COLLATE\s+[" \']?([^\s," \')]+)}is ' ;
511
+ $ pattern = '{ ' . $ this ->buildIdentifierPattern ($ column )
512
+ . '[^,(]+(?:\([^()]+\)[^,]*)?(?:(?:DEFAULT|CHECK)\s*(?:\(.*?\))?[^,]*)*COLLATE\s+[" \']?([^\s," \')]+)}is ' ;
514
513
515
514
if (preg_match ($ pattern , $ sql , $ match ) !== 1 ) {
516
515
return null ;
@@ -522,9 +521,7 @@ private function parseColumnCollationFromSQL(string $column, string $sql): ?stri
522
521
private function parseTableCommentFromSQL (string $ table , string $ sql ): ?string
523
522
{
524
523
$ pattern = '/\s* # Allow whitespace characters at start of line
525
- CREATE\sTABLE # Match "CREATE TABLE"
526
- (?:\W" ' . preg_quote ($ this ->_platform ->quoteSingleIdentifier ($ table ), '/ ' ) . '"\W|\W ' . preg_quote ($ table , '/ ' )
527
- . '\W) # Match table name (quoted and unquoted)
524
+ CREATE\sTABLE ' . $ this ->buildIdentifierPattern ($ table ) . '
528
525
( # Start capture
529
526
(?:\s*--[^\n]*\n?)+ # Capture anything that starts with whitespaces followed by -- until the end of the line(s)
530
527
)/ix ' ;
@@ -540,8 +537,8 @@ private function parseTableCommentFromSQL(string $table, string $sql): ?string
540
537
541
538
private function parseColumnCommentFromSQL (string $ column , string $ sql ): ?string
542
539
{
543
- $ pattern = '{[\s(,](?:\W ' . preg_quote ( $ this ->_platform -> quoteSingleIdentifier ($ column) )
544
- . '\W|\W ' . preg_quote ( $ column ) . ' \W) (?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i ' ;
540
+ $ pattern = '{[\s(,] ' . $ this ->buildIdentifierPattern ($ column )
541
+ . '(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i ' ;
545
542
546
543
if (preg_match ($ pattern , $ sql , $ match ) !== 1 ) {
547
544
return null ;
@@ -552,6 +549,22 @@ private function parseColumnCommentFromSQL(string $column, string $sql): ?string
552
549
return $ comment === '' ? null : $ comment ;
553
550
}
554
551
552
+ /**
553
+ * Returns a regular expression pattern that matches the given unquoted or quoted identifier.
554
+ */
555
+ private function buildIdentifierPattern (string $ identifier ): string
556
+ {
557
+ return '(?: ' . implode ('| ' , array_map (
558
+ static function (string $ sql ): string {
559
+ return '\W ' . preg_quote ($ sql , '/ ' ) . '\W ' ;
560
+ },
561
+ [
562
+ $ identifier ,
563
+ $ this ->_platform ->quoteSingleIdentifier ($ identifier ),
564
+ ],
565
+ )) . ') ' ;
566
+ }
567
+
555
568
/** @throws Exception */
556
569
private function getCreateTableSQL (string $ table ): string
557
570
{
0 commit comments