| @@ 771-788 (lines=18) @@ | ||
| 768 | * |
|
| 769 | * @todo Where is this used? Which information should be retrieved? |
|
| 770 | */ |
|
| 771 | public function getListTableConstraintsSQL($table) |
|
| 772 | { |
|
| 773 | $user = ''; |
|
| 774 | ||
| 775 | if (strpos($table, '.') !== false) { |
|
| 776 | list($user, $table) = explode('.', $table); |
|
| 777 | $user = $this->quoteStringLiteral($user); |
|
| 778 | $table = $this->quoteStringLiteral($table); |
|
| 779 | } else { |
|
| 780 | $table = $this->quoteStringLiteral($table); |
|
| 781 | } |
|
| 782 | ||
| 783 | return "SELECT con.* |
|
| 784 | FROM SYS.SYSCONSTRAINT AS con |
|
| 785 | JOIN SYS.SYSTAB AS tab ON con.table_object_id = tab.object_id |
|
| 786 | WHERE tab.table_name = $table |
|
| 787 | AND tab.creator = USER_ID($user)"; |
|
| 788 | } |
|
| 789 | ||
| 790 | /** |
|
| 791 | * {@inheritdoc} |
|
| @@ 793-874 (lines=82) @@ | ||
| 790 | /** |
|
| 791 | * {@inheritdoc} |
|
| 792 | */ |
|
| 793 | public function getListTableForeignKeysSQL($table) |
|
| 794 | { |
|
| 795 | $user = ''; |
|
| 796 | ||
| 797 | if (strpos($table, '.') !== false) { |
|
| 798 | list($user, $table) = explode('.', $table); |
|
| 799 | $user = $this->quoteStringLiteral($user); |
|
| 800 | $table = $this->quoteStringLiteral($table); |
|
| 801 | } else { |
|
| 802 | $table = $this->quoteStringLiteral($table); |
|
| 803 | } |
|
| 804 | ||
| 805 | return "SELECT fcol.column_name AS local_column, |
|
| 806 | ptbl.table_name AS foreign_table, |
|
| 807 | pcol.column_name AS foreign_column, |
|
| 808 | idx.index_name, |
|
| 809 | IF fk.nulls = 'N' |
|
| 810 | THEN 1 |
|
| 811 | ELSE NULL |
|
| 812 | ENDIF AS notnull, |
|
| 813 | CASE ut.referential_action |
|
| 814 | WHEN 'C' THEN 'CASCADE' |
|
| 815 | WHEN 'D' THEN 'SET DEFAULT' |
|
| 816 | WHEN 'N' THEN 'SET NULL' |
|
| 817 | WHEN 'R' THEN 'RESTRICT' |
|
| 818 | ELSE NULL |
|
| 819 | END AS on_update, |
|
| 820 | CASE dt.referential_action |
|
| 821 | WHEN 'C' THEN 'CASCADE' |
|
| 822 | WHEN 'D' THEN 'SET DEFAULT' |
|
| 823 | WHEN 'N' THEN 'SET NULL' |
|
| 824 | WHEN 'R' THEN 'RESTRICT' |
|
| 825 | ELSE NULL |
|
| 826 | END AS on_delete, |
|
| 827 | IF fk.check_on_commit = 'Y' |
|
| 828 | THEN 1 |
|
| 829 | ELSE NULL |
|
| 830 | ENDIF AS check_on_commit, -- check_on_commit flag |
|
| 831 | IF ftbl.clustered_index_id = idx.index_id |
|
| 832 | THEN 1 |
|
| 833 | ELSE NULL |
|
| 834 | ENDIF AS 'clustered', -- clustered flag |
|
| 835 | IF fk.match_type = 0 |
|
| 836 | THEN NULL |
|
| 837 | ELSE fk.match_type |
|
| 838 | ENDIF AS 'match', -- match option |
|
| 839 | IF pidx.max_key_distance = 1 |
|
| 840 | THEN 1 |
|
| 841 | ELSE NULL |
|
| 842 | ENDIF AS for_olap_workload -- for_olap_workload flag |
|
| 843 | FROM SYS.SYSFKEY AS fk |
|
| 844 | JOIN SYS.SYSIDX AS idx |
|
| 845 | ON fk.foreign_table_id = idx.table_id |
|
| 846 | AND fk.foreign_index_id = idx.index_id |
|
| 847 | JOIN SYS.SYSPHYSIDX pidx |
|
| 848 | ON idx.table_id = pidx.table_id |
|
| 849 | AND idx.phys_index_id = pidx.phys_index_id |
|
| 850 | JOIN SYS.SYSTAB AS ptbl |
|
| 851 | ON fk.primary_table_id = ptbl.table_id |
|
| 852 | JOIN SYS.SYSTAB AS ftbl |
|
| 853 | ON fk.foreign_table_id = ftbl.table_id |
|
| 854 | JOIN SYS.SYSIDXCOL AS idxcol |
|
| 855 | ON idx.table_id = idxcol.table_id |
|
| 856 | AND idx.index_id = idxcol.index_id |
|
| 857 | JOIN SYS.SYSTABCOL AS pcol |
|
| 858 | ON ptbl.table_id = pcol.table_id |
|
| 859 | AND idxcol.primary_column_id = pcol.column_id |
|
| 860 | JOIN SYS.SYSTABCOL AS fcol |
|
| 861 | ON ftbl.table_id = fcol.table_id |
|
| 862 | AND idxcol.column_id = fcol.column_id |
|
| 863 | LEFT JOIN SYS.SYSTRIGGER ut |
|
| 864 | ON fk.foreign_table_id = ut.foreign_table_id |
|
| 865 | AND fk.foreign_index_id = ut.foreign_key_id |
|
| 866 | AND ut.event = 'C' |
|
| 867 | LEFT JOIN SYS.SYSTRIGGER dt |
|
| 868 | ON fk.foreign_table_id = dt.foreign_table_id |
|
| 869 | AND fk.foreign_index_id = dt.foreign_key_id |
|
| 870 | AND dt.event = 'D' |
|
| 871 | WHERE ftbl.table_name = $table |
|
| 872 | AND ftbl.creator = USER_ID($user) |
|
| 873 | ORDER BY fk.foreign_index_id ASC, idxcol.sequence ASC"; |
|
| 874 | } |
|
| 875 | ||
| 876 | /** |
|
| 877 | * {@inheritdoc} |
|
| @@ 879-927 (lines=49) @@ | ||
| 876 | /** |
|
| 877 | * {@inheritdoc} |
|
| 878 | */ |
|
| 879 | public function getListTableIndexesSQL($table, $currentDatabase = null) |
|
| 880 | { |
|
| 881 | $user = ''; |
|
| 882 | ||
| 883 | if (strpos($table, '.') !== false) { |
|
| 884 | list($user, $table) = explode('.', $table); |
|
| 885 | $user = $this->quoteStringLiteral($user); |
|
| 886 | $table = $this->quoteStringLiteral($table); |
|
| 887 | } else { |
|
| 888 | $table = $this->quoteStringLiteral($table); |
|
| 889 | } |
|
| 890 | ||
| 891 | return "SELECT idx.index_name AS key_name, |
|
| 892 | IF idx.index_category = 1 |
|
| 893 | THEN 1 |
|
| 894 | ELSE 0 |
|
| 895 | ENDIF AS 'primary', |
|
| 896 | col.column_name, |
|
| 897 | IF idx.\"unique\" IN(1, 2, 5) |
|
| 898 | THEN 0 |
|
| 899 | ELSE 1 |
|
| 900 | ENDIF AS non_unique, |
|
| 901 | IF tbl.clustered_index_id = idx.index_id |
|
| 902 | THEN 1 |
|
| 903 | ELSE NULL |
|
| 904 | ENDIF AS 'clustered', -- clustered flag |
|
| 905 | IF idx.\"unique\" = 5 |
|
| 906 | THEN 1 |
|
| 907 | ELSE NULL |
|
| 908 | ENDIF AS with_nulls_not_distinct, -- with_nulls_not_distinct flag |
|
| 909 | IF pidx.max_key_distance = 1 |
|
| 910 | THEN 1 |
|
| 911 | ELSE NULL |
|
| 912 | ENDIF AS for_olap_workload -- for_olap_workload flag |
|
| 913 | FROM SYS.SYSIDX AS idx |
|
| 914 | JOIN SYS.SYSPHYSIDX pidx |
|
| 915 | ON idx.table_id = pidx.table_id |
|
| 916 | AND idx.phys_index_id = pidx.phys_index_id |
|
| 917 | JOIN SYS.SYSIDXCOL AS idxcol |
|
| 918 | ON idx.table_id = idxcol.table_id AND idx.index_id = idxcol.index_id |
|
| 919 | JOIN SYS.SYSTABCOL AS col |
|
| 920 | ON idxcol.table_id = col.table_id AND idxcol.column_id = col.column_id |
|
| 921 | JOIN SYS.SYSTAB AS tbl |
|
| 922 | ON idx.table_id = tbl.table_id |
|
| 923 | WHERE tbl.table_name = $table |
|
| 924 | AND tbl.creator = USER_ID($user) |
|
| 925 | AND idx.index_category != 2 -- exclude indexes implicitly created by foreign key constraints |
|
| 926 | ORDER BY idx.index_id ASC, idxcol.sequence ASC"; |
|
| 927 | } |
|
| 928 | ||
| 929 | /** |
|
| 930 | * {@inheritdoc} |
|