| @@ 688-710 (lines=23) @@ | ||
| 685 | /** |
|
| 686 | * {@inheritdoc} |
|
| 687 | */ |
|
| 688 | public function dropIndex($tableName, $columns) |
|
| 689 | { |
|
| 690 | if (is_string($columns)) { |
|
| 691 | $columns = [$columns]; // str to array |
|
| 692 | } |
|
| 693 | ||
| 694 | $indexes = $this->getIndexes($tableName); |
|
| 695 | $columns = array_map('strtolower', $columns); |
|
| 696 | ||
| 697 | foreach ($indexes as $indexName => $index) { |
|
| 698 | $a = array_diff($columns, $index['columns']); |
|
| 699 | if (empty($a)) { |
|
| 700 | $this->execute( |
|
| 701 | sprintf( |
|
| 702 | 'DROP INDEX %s ON %s', |
|
| 703 | $this->quoteColumnName($indexName), |
|
| 704 | $this->quoteTableName($tableName) |
|
| 705 | ) |
|
| 706 | ); |
|
| 707 | return; |
|
| 708 | } |
|
| 709 | } |
|
| 710 | } |
|
| 711 | ||
| 712 | /** |
|
| 713 | * {@inheritdoc} |
|
| @@ 808-845 (lines=38) @@ | ||
| 805 | /** |
|
| 806 | * {@inheritdoc} |
|
| 807 | */ |
|
| 808 | public function dropForeignKey($tableName, $columns, $constraint = null) |
|
| 809 | { |
|
| 810 | if (is_string($columns)) { |
|
| 811 | $columns = [$columns]; // str to array |
|
| 812 | } |
|
| 813 | ||
| 814 | if ($constraint) { |
|
| 815 | $this->execute( |
|
| 816 | sprintf( |
|
| 817 | 'ALTER TABLE %s DROP CONSTRAINT %s', |
|
| 818 | $this->quoteTableName($tableName), |
|
| 819 | $constraint |
|
| 820 | ) |
|
| 821 | ); |
|
| 822 | return; |
|
| 823 | } else { |
|
| 824 | foreach ($columns as $column) { |
|
| 825 | $rows = $this->fetchAll(sprintf( |
|
| 826 | "SELECT |
|
| 827 | tc.constraint_name, |
|
| 828 | tc.table_name, kcu.column_name, |
|
| 829 | ccu.table_name AS referenced_table_name, |
|
| 830 | ccu.column_name AS referenced_column_name |
|
| 831 | FROM |
|
| 832 | information_schema.table_constraints AS tc |
|
| 833 | JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name |
|
| 834 | JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name |
|
| 835 | WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name = '%s' and ccu.column_name='%s' |
|
| 836 | ORDER BY kcu.ordinal_position", |
|
| 837 | $tableName, |
|
| 838 | $column |
|
| 839 | )); |
|
| 840 | foreach ($rows as $row) { |
|
| 841 | $this->dropForeignKey($tableName, $columns, $row['constraint_name']); |
|
| 842 | } |
|
| 843 | } |
|
| 844 | } |
|
| 845 | } |
|
| 846 | ||
| 847 | /** |
|
| 848 | * {@inheritdoc} |
|
| @@ 653-688 (lines=36) @@ | ||
| 650 | /** |
|
| 651 | * {@inheritdoc} |
|
| 652 | */ |
|
| 653 | public function dropForeignKey($tableName, $columns, $constraint = null) |
|
| 654 | { |
|
| 655 | if (is_string($columns)) { |
|
| 656 | $columns = [$columns]; // str to array |
|
| 657 | } |
|
| 658 | ||
| 659 | ||
| 660 | if ($constraint) { |
|
| 661 | $this->execute( |
|
| 662 | sprintf( |
|
| 663 | 'ALTER TABLE %s DROP FOREIGN KEY %s', |
|
| 664 | $this->quoteTableName($tableName), |
|
| 665 | $constraint |
|
| 666 | ) |
|
| 667 | ); |
|
| 668 | return; |
|
| 669 | } else { |
|
| 670 | foreach ($columns as $column) { |
|
| 671 | $rows = $this->fetchAll(sprintf( |
|
| 672 | "SELECT |
|
| 673 | CONSTRAINT_NAME |
|
| 674 | FROM information_schema.KEY_COLUMN_USAGE |
|
| 675 | WHERE REFERENCED_TABLE_SCHEMA = DATABASE() |
|
| 676 | AND REFERENCED_TABLE_NAME IS NOT NULL |
|
| 677 | AND TABLE_NAME = '%s' |
|
| 678 | AND COLUMN_NAME = '%s' |
|
| 679 | ORDER BY POSITION_IN_UNIQUE_CONSTRAINT", |
|
| 680 | $tableName, |
|
| 681 | $column |
|
| 682 | )); |
|
| 683 | foreach ($rows as $row) { |
|
| 684 | $this->dropForeignKey($tableName, $columns, $row['CONSTRAINT_NAME']); |
|
| 685 | } |
|
| 686 | } |
|
| 687 | } |
|
| 688 | } |
|
| 689 | ||
| 690 | /** |
|
| 691 | * {@inheritdoc} |
|
| @@ 681-714 (lines=34) @@ | ||
| 678 | /** |
|
| 679 | * {@inheritdoc} |
|
| 680 | */ |
|
| 681 | public function dropForeignKey($tableName, $columns, $constraint = null) |
|
| 682 | { |
|
| 683 | if (is_string($columns)) { |
|
| 684 | $columns = [$columns]; // str to array |
|
| 685 | } |
|
| 686 | ||
| 687 | if ($constraint) { |
|
| 688 | $this->execute( |
|
| 689 | sprintf( |
|
| 690 | 'ALTER TABLE %s DROP CONSTRAINT %s', |
|
| 691 | $this->quoteTableName($tableName), |
|
| 692 | $constraint |
|
| 693 | ) |
|
| 694 | ); |
|
| 695 | } else { |
|
| 696 | foreach ($columns as $column) { |
|
| 697 | $rows = $this->fetchAll(sprintf( |
|
| 698 | "SELECT CONSTRAINT_NAME |
|
| 699 | FROM information_schema.KEY_COLUMN_USAGE |
|
| 700 | WHERE TABLE_SCHEMA = CURRENT_SCHEMA() |
|
| 701 | AND TABLE_NAME IS NOT NULL |
|
| 702 | AND TABLE_NAME = '%s' |
|
| 703 | AND COLUMN_NAME = '%s' |
|
| 704 | ORDER BY POSITION_IN_UNIQUE_CONSTRAINT", |
|
| 705 | $tableName, |
|
| 706 | $column |
|
| 707 | )); |
|
| 708 | ||
| 709 | foreach ($rows as $row) { |
|
| 710 | $this->dropForeignKey($tableName, $columns, $row['constraint_name']); |
|
| 711 | } |
|
| 712 | } |
|
| 713 | } |
|
| 714 | } |
|
| 715 | ||
| 716 | /** |
|
| 717 | * {@inheritdoc} |
|