From ba31b5beb315d66a85e118edea428b3e1c8017ed Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Thu, 19 Apr 2007 01:35:15 +0000 Subject: [PATCH] Add constraintExists function, mild cleanup of other nearby funcs. --- includes/DatabasePostgres.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/includes/DatabasePostgres.php b/includes/DatabasePostgres.php index 4e28dc146e..f2b982d629 100644 --- a/includes/DatabasePostgres.php +++ b/includes/DatabasePostgres.php @@ -880,7 +880,7 @@ class DatabasePostgres extends Database { } function triggerExists($table, $trigger) { - global $wgDBmwschema; + global $wgDBmwschema; $q = <<addQuotes($wgDBmwschema), $this->addQuotes($table), $this->addQuotes($trigger))); - $row = $this->fetchRow($res); - $exists = !!$row; + if (!$res) + return NULL; + $rows = pg_num_rows($res); $this->freeResult($res); - return $exists; + return $rows; } function ruleExists($table, $rule) { - global $wgDBmwschema; + global $wgDBmwschema; $exists = $this->selectField("pg_rules", "rulename", array( "rulename" => $rule, "tablename" => $table, @@ -907,6 +908,21 @@ END; return $exists === $rule; } + function constraintExists($table, $constraint) { + global $wgDBmwschema; + $SQL = sprintf("SELECT 1 FROM information_schema.table_constraints ". + "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s", + $this->addQuotes($wgDBmwschema), + $this->addQuotes($table), + $this->addQuotes($constraint)); + $res = $this->query($SQL); + if (!$res) + return NULL; + $rows = pg_num_rows($res); + $this->freeResult($res); + return $rows; + } + /** * Query whether a given schema exists. Returns the name of the owner */ -- 2.20.1