| @@ 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} |
|
| @@ 736-761 (lines=26) @@ | ||
| 733 | * @param string $tableName Table Name |
|
| 734 | * @return array |
|
| 735 | */ |
|
| 736 | protected function getForeignKeys($tableName) |
|
| 737 | { |
|
| 738 | $foreignKeys = []; |
|
| 739 | $rows = $this->fetchAll(sprintf( |
|
| 740 | "SELECT |
|
| 741 | CONSTRAINT_NAME, |
|
| 742 | TABLE_NAME, |
|
| 743 | COLUMN_NAME, |
|
| 744 | REFERENCED_TABLE_NAME, |
|
| 745 | REFERENCED_COLUMN_NAME |
|
| 746 | FROM information_schema.KEY_COLUMN_USAGE |
|
| 747 | WHERE REFERENCED_TABLE_SCHEMA = DATABASE() |
|
| 748 | AND REFERENCED_TABLE_NAME IS NOT NULL |
|
| 749 | AND TABLE_NAME = '%s' |
|
| 750 | ORDER BY POSITION_IN_UNIQUE_CONSTRAINT", |
|
| 751 | $tableName |
|
| 752 | )); |
|
| 753 | foreach ($rows as $row) { |
|
| 754 | $foreignKeys[$row['CONSTRAINT_NAME']]['table'] = $row['TABLE_NAME']; |
|
| 755 | $foreignKeys[$row['CONSTRAINT_NAME']]['columns'][] = $row['COLUMN_NAME']; |
|
| 756 | $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table'] = $row['REFERENCED_TABLE_NAME']; |
|
| 757 | $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME']; |
|
| 758 | } |
|
| 759 | ||
| 760 | return $foreignKeys; |
|
| 761 | } |
|
| 762 | ||
| 763 | /** |
|
| 764 | * {@inheritdoc} |
|