| @@ 636-660 (lines=25) @@ | ||
| 633 | * @param string $tableName Table Name |
|
| 634 | * @return array |
|
| 635 | */ |
|
| 636 | protected function getForeignKeys($tableName) |
|
| 637 | { |
|
| 638 | $foreignKeys = []; |
|
| 639 | $rows = $this->fetchAll(sprintf( |
|
| 640 | "SELECT |
|
| 641 | tc.constraint_name, |
|
| 642 | tc.table_name, kcu.column_name, |
|
| 643 | ccu.table_name AS referenced_table_name, |
|
| 644 | ccu.column_name AS referenced_column_name |
|
| 645 | FROM |
|
| 646 | information_schema.table_constraints AS tc |
|
| 647 | JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name |
|
| 648 | JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name |
|
| 649 | WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s' |
|
| 650 | ORDER BY kcu.position_in_unique_constraint", |
|
| 651 | $tableName |
|
| 652 | )); |
|
| 653 | foreach ($rows as $row) { |
|
| 654 | $foreignKeys[$row['constraint_name']]['table'] = $row['table_name']; |
|
| 655 | $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name']; |
|
| 656 | $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name']; |
|
| 657 | $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name']; |
|
| 658 | } |
|
| 659 | ||
| 660 | return $foreignKeys; |
|
| 661 | } |
|
| 662 | ||
| 663 | /** |
|
| @@ 762-787 (lines=26) @@ | ||
| 759 | * @param string $tableName Table Name |
|
| 760 | * @return array |
|
| 761 | */ |
|
| 762 | protected function getForeignKeys($tableName) |
|
| 763 | { |
|
| 764 | $foreignKeys = []; |
|
| 765 | $rows = $this->fetchAll(sprintf( |
|
| 766 | "SELECT |
|
| 767 | tc.constraint_name, |
|
| 768 | tc.table_name, kcu.column_name, |
|
| 769 | ccu.table_name AS referenced_table_name, |
|
| 770 | ccu.column_name AS referenced_column_name |
|
| 771 | FROM |
|
| 772 | information_schema.table_constraints AS tc |
|
| 773 | JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name |
|
| 774 | JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name |
|
| 775 | WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s' |
|
| 776 | ORDER BY kcu.ordinal_position", |
|
| 777 | $tableName |
|
| 778 | )); |
|
| 779 | foreach ($rows as $row) { |
|
| 780 | $foreignKeys[$row['constraint_name']]['table'] = $row['table_name']; |
|
| 781 | $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name']; |
|
| 782 | $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name']; |
|
| 783 | $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name']; |
|
| 784 | } |
|
| 785 | ||
| 786 | return $foreignKeys; |
|
| 787 | } |
|
| 788 | ||
| 789 | /** |
|
| 790 | * {@inheritdoc} |
|
| @@ 632-656 (lines=25) @@ | ||
| 629 | * @param string $tableName Table Name |
|
| 630 | * @return array |
|
| 631 | */ |
|
| 632 | protected function getForeignKeys($tableName) |
|
| 633 | { |
|
| 634 | $foreignKeys = []; |
|
| 635 | $rows = $this->fetchAll(sprintf( |
|
| 636 | "SELECT |
|
| 637 | CONSTRAINT_NAME, |
|
| 638 | TABLE_NAME, |
|
| 639 | COLUMN_NAME, |
|
| 640 | REFERENCED_TABLE_NAME, |
|
| 641 | REFERENCED_COLUMN_NAME |
|
| 642 | FROM information_schema.KEY_COLUMN_USAGE |
|
| 643 | WHERE REFERENCED_TABLE_SCHEMA = DATABASE() |
|
| 644 | AND REFERENCED_TABLE_NAME IS NOT NULL |
|
| 645 | AND TABLE_NAME = '%s' |
|
| 646 | ORDER BY POSITION_IN_UNIQUE_CONSTRAINT", |
|
| 647 | $tableName |
|
| 648 | )); |
|
| 649 | foreach ($rows as $row) { |
|
| 650 | $foreignKeys[$row['CONSTRAINT_NAME']]['table'] = $row['TABLE_NAME']; |
|
| 651 | $foreignKeys[$row['CONSTRAINT_NAME']]['columns'][] = $row['COLUMN_NAME']; |
|
| 652 | $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table'] = $row['REFERENCED_TABLE_NAME']; |
|
| 653 | $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME']; |
|
| 654 | } |
|
| 655 | ||
| 656 | return $foreignKeys; |
|
| 657 | } |
|
| 658 | ||
| 659 | /** |
|
| @@ 634-656 (lines=23) @@ | ||
| 631 | * @param string $type Type of Constraint Type (R, P) |
|
| 632 | * @return array |
|
| 633 | */ |
|
| 634 | protected function getForeignKeys($tableName, $type = 'R') |
|
| 635 | { |
|
| 636 | $foreignKeys = []; |
|
| 637 | $rows = $this->fetchAll(sprintf( |
|
| 638 | "SELECT a.CONSTRAINT_NAME, a.TABLE_NAME, b.COLUMN_NAME, |
|
| 639 | (SELECT c.TABLE_NAME from ALL_CONS_COLUMNS c |
|
| 640 | WHERE c.CONSTRAINT_NAME = a.R_CONSTRAINT_NAME) referenced_table_name, |
|
| 641 | (SELECT c.COLUMN_NAME from ALL_CONS_COLUMNS c |
|
| 642 | WHERE c.CONSTRAINT_NAME = a.R_CONSTRAINT_NAME) referenced_column_name |
|
| 643 | FROM all_constraints a JOIN ALL_CONS_COLUMNS b ON a.CONSTRAINT_NAME = b.CONSTRAINT_NAME |
|
| 644 | WHERE a.table_name = '%s' |
|
| 645 | AND CONSTRAINT_TYPE = '%s'", |
|
| 646 | $tableName, |
|
| 647 | $type |
|
| 648 | )); |
|
| 649 | ||
| 650 | foreach ($rows as $row) { |
|
| 651 | $foreignKeys[$row['CONSTRAINT_NAME']]['TABLE'] = $row['TABLE_NAME']; |
|
| 652 | $foreignKeys[$row['CONSTRAINT_NAME']]['COLUMNS'][] = $row['COLUMN_NAME']; |
|
| 653 | $foreignKeys[$row['CONSTRAINT_NAME']]['REFERENCED_TABLE'] = $row['REFERENCED_TABLE_NAME']; |
|
| 654 | $foreignKeys[$row['CONSTRAINT_NAME']]['REFERENCED_COLUMNS'][] = $row['REFERENCED_COLUMN_NAME']; |
|
| 655 | } |
|
| 656 | ||
| 657 | return $foreignKeys; |
|
| 658 | } |
|
| 659 | ||