| @@ 743-768 (lines=26) @@ | ||
| 740 | * @param string $tableName Table Name |
|
| 741 | * @return array |
|
| 742 | */ |
|
| 743 | protected function getForeignKeys($tableName) |
|
| 744 | { |
|
| 745 | $foreignKeys = []; |
|
| 746 | $rows = $this->fetchAll(sprintf( |
|
| 747 | "SELECT |
|
| 748 | CONSTRAINT_NAME, |
|
| 749 | TABLE_NAME, |
|
| 750 | COLUMN_NAME, |
|
| 751 | REFERENCED_TABLE_NAME, |
|
| 752 | REFERENCED_COLUMN_NAME |
|
| 753 | FROM information_schema.KEY_COLUMN_USAGE |
|
| 754 | WHERE REFERENCED_TABLE_SCHEMA = DATABASE() |
|
| 755 | AND REFERENCED_TABLE_NAME IS NOT NULL |
|
| 756 | AND TABLE_NAME = '%s' |
|
| 757 | ORDER BY POSITION_IN_UNIQUE_CONSTRAINT", |
|
| 758 | $tableName |
|
| 759 | )); |
|
| 760 | foreach ($rows as $row) { |
|
| 761 | $foreignKeys[$row['CONSTRAINT_NAME']]['table'] = $row['TABLE_NAME']; |
|
| 762 | $foreignKeys[$row['CONSTRAINT_NAME']]['columns'][] = $row['COLUMN_NAME']; |
|
| 763 | $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table'] = $row['REFERENCED_TABLE_NAME']; |
|
| 764 | $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME']; |
|
| 765 | } |
|
| 766 | ||
| 767 | return $foreignKeys; |
|
| 768 | } |
|
| 769 | ||
| 770 | /** |
|
| 771 | * {@inheritdoc} |
|
| @@ 897-922 (lines=26) @@ | ||
| 894 | * @param string $tableName Table Name |
|
| 895 | * @return array |
|
| 896 | */ |
|
| 897 | protected function getForeignKeys($tableName) |
|
| 898 | { |
|
| 899 | $foreignKeys = []; |
|
| 900 | $rows = $this->fetchAll(sprintf( |
|
| 901 | "SELECT |
|
| 902 | tc.constraint_name, |
|
| 903 | tc.table_name, kcu.column_name, |
|
| 904 | ccu.table_name AS referenced_table_name, |
|
| 905 | ccu.column_name AS referenced_column_name |
|
| 906 | FROM |
|
| 907 | information_schema.table_constraints AS tc |
|
| 908 | JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name |
|
| 909 | JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name |
|
| 910 | WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s' |
|
| 911 | ORDER BY kcu.ordinal_position", |
|
| 912 | $tableName |
|
| 913 | )); |
|
| 914 | foreach ($rows as $row) { |
|
| 915 | $foreignKeys[$row['constraint_name']]['table'] = $row['table_name']; |
|
| 916 | $foreignKeys[$row['constraint_name']]['columns'][] = $row['column_name']; |
|
| 917 | $foreignKeys[$row['constraint_name']]['referenced_table'] = $row['referenced_table_name']; |
|
| 918 | $foreignKeys[$row['constraint_name']]['referenced_columns'][] = $row['referenced_column_name']; |
|
| 919 | } |
|
| 920 | ||
| 921 | return $foreignKeys; |
|
| 922 | } |
|
| 923 | ||
| 924 | /** |
|
| 925 | * {@inheritdoc} |
|