Index: trunk/phase3/includes/DatabasePostgres.php |
— | — | @@ -880,7 +880,7 @@ |
881 | 881 | } |
882 | 882 | |
883 | 883 | function triggerExists($table, $trigger) { |
884 | | - global $wgDBmwschema; |
| 884 | + global $wgDBmwschema; |
885 | 885 | |
886 | 886 | $q = <<<END |
887 | 887 | SELECT 1 FROM pg_class, pg_namespace, pg_trigger |
— | — | @@ -892,14 +892,15 @@ |
893 | 893 | $this->addQuotes($wgDBmwschema), |
894 | 894 | $this->addQuotes($table), |
895 | 895 | $this->addQuotes($trigger))); |
896 | | - $row = $this->fetchRow($res); |
897 | | - $exists = !!$row; |
| 896 | + if (!$res) |
| 897 | + return NULL; |
| 898 | + $rows = pg_num_rows($res); |
898 | 899 | $this->freeResult($res); |
899 | | - return $exists; |
| 900 | + return $rows; |
900 | 901 | } |
901 | 902 | |
902 | 903 | function ruleExists($table, $rule) { |
903 | | - global $wgDBmwschema; |
| 904 | + global $wgDBmwschema; |
904 | 905 | $exists = $this->selectField("pg_rules", "rulename", |
905 | 906 | array( "rulename" => $rule, |
906 | 907 | "tablename" => $table, |
— | — | @@ -907,6 +908,21 @@ |
908 | 909 | return $exists === $rule; |
909 | 910 | } |
910 | 911 | |
| 912 | + function constraintExists($table, $constraint) { |
| 913 | + global $wgDBmwschema; |
| 914 | + $SQL = sprintf("SELECT 1 FROM information_schema.table_constraints ". |
| 915 | + "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s", |
| 916 | + $this->addQuotes($wgDBmwschema), |
| 917 | + $this->addQuotes($table), |
| 918 | + $this->addQuotes($constraint)); |
| 919 | + $res = $this->query($SQL); |
| 920 | + if (!$res) |
| 921 | + return NULL; |
| 922 | + $rows = pg_num_rows($res); |
| 923 | + $this->freeResult($res); |
| 924 | + return $rows; |
| 925 | + } |
| 926 | + |
911 | 927 | /** |
912 | 928 | * Query whether a given schema exists. Returns the name of the owner |
913 | 929 | */ |