r21358 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r21357‎ | r21358 | r21359 >
Date:01:35, 19 April 2007
Author:greg
Status:old
Tags:
Comment:
Add constraintExists function, mild cleanup of other nearby funcs.
Modified paths:
  • /trunk/phase3/includes/DatabasePostgres.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DatabasePostgres.php
@@ -880,7 +880,7 @@
881881 }
882882
883883 function triggerExists($table, $trigger) {
884 - global $wgDBmwschema;
 884+ global $wgDBmwschema;
885885
886886 $q = <<<END
887887 SELECT 1 FROM pg_class, pg_namespace, pg_trigger
@@ -892,14 +892,15 @@
893893 $this->addQuotes($wgDBmwschema),
894894 $this->addQuotes($table),
895895 $this->addQuotes($trigger)));
896 - $row = $this->fetchRow($res);
897 - $exists = !!$row;
 896+ if (!$res)
 897+ return NULL;
 898+ $rows = pg_num_rows($res);
898899 $this->freeResult($res);
899 - return $exists;
 900+ return $rows;
900901 }
901902
902903 function ruleExists($table, $rule) {
903 - global $wgDBmwschema;
 904+ global $wgDBmwschema;
904905 $exists = $this->selectField("pg_rules", "rulename",
905906 array( "rulename" => $rule,
906907 "tablename" => $table,
@@ -907,6 +908,21 @@
908909 return $exists === $rule;
909910 }
910911
 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+
911927 /**
912928 * Query whether a given schema exists. Returns the name of the owner
913929 */