From 4bd9ac8fffcb8ad1ceaf6aa49ebcd434be982f37 Mon Sep 17 00:00:00 2001 From: soranzo Date: Wed, 28 Mar 2007 18:52:34 +0000 Subject: [PATCH] Bugfix: alterDatabase for 8.2 didn't use transactions and didn't change the owner. --- classes/database/Postgres74.php | 5 +++-- classes/database/Postgres80.php | 6 ++++-- classes/database/Postgres82.php | 38 +++++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/classes/database/Postgres74.php b/classes/database/Postgres74.php index b15998bc..83e469a0 100644 --- a/classes/database/Postgres74.php +++ b/classes/database/Postgres74.php @@ -4,7 +4,7 @@ * A class that implements the DB interface for Postgres * Note: This class uses ADODB and returns RecordSets. * - * $Id: Postgres74.php,v 1.56 2007/01/10 02:01:17 soranzo Exp $ + * $Id: Postgres74.php,v 1.57 2007/03/28 18:52:34 soranzo Exp $ */ include_once('./classes/database/Postgres73.php'); @@ -50,9 +50,10 @@ class Postgres74 extends Postgres73 { * @return -2 owner error * @return -3 rename error */ - function alterDatabase($dbName, $newName, $newOwner = '') + function alterDatabase($dbName, $newName, $newOwner = '', $comment = '') { //ignore $newowner, not supported pre 8.0 + //ignore $comment, not supported pre 8.2 $this->clean($dbName); $this->clean($newName); diff --git a/classes/database/Postgres80.php b/classes/database/Postgres80.php index b1bb5e8f..77918358 100644 --- a/classes/database/Postgres80.php +++ b/classes/database/Postgres80.php @@ -3,7 +3,7 @@ /** * PostgreSQL 8.0 support * - * $Id: Postgres80.php,v 1.21 2006/12/31 15:35:49 xzilla Exp $ + * $Id: Postgres80.php,v 1.22 2007/03/28 18:52:34 soranzo Exp $ */ include_once('./classes/database/Postgres74.php'); @@ -94,11 +94,12 @@ class Postgres80 extends Postgres74 { * @return -2 owner error * @return -3 rename error */ - function alterDatabase($dbName, $newName, $newOwner = '') + function alterDatabase($dbName, $newName, $newOwner = '', $comment = '') { $this->clean($dbName); $this->clean($newName); $this->clean($newOwner); + //ignore $comment, not supported pre 8.2 $status = $this->beginTransaction(); if ($status != 0) { @@ -121,6 +122,7 @@ class Postgres80 extends Postgres74 { } return $this->endTransaction(); } + /** * Changes ownership of a database * This can only be done by a superuser or the owner of the database diff --git a/classes/database/Postgres82.php b/classes/database/Postgres82.php index 6f8fb105..0ef5664b 100644 --- a/classes/database/Postgres82.php +++ b/classes/database/Postgres82.php @@ -3,7 +3,7 @@ /** * PostgreSQL 8.2 support * - * $Id: Postgres82.php,v 1.4 2006/12/31 19:06:16 xzilla Exp $ + * $Id: Postgres82.php,v 1.5 2007/03/28 18:52:34 soranzo Exp $ */ include_once('./classes/database/Postgres81.php'); @@ -112,21 +112,41 @@ class Postgres82 extends Postgres81 { * @return -3 rename error * @return -4 comment error */ - function alterDatabase($dbName, $newName, $newOwner = '',$comment = '') + function alterDatabase($dbName, $newName, $newOwner = '', $comment = '') { - //ignore $newowner, not supported pre 8.0 - //ignore $comment, not supported pre 8.2 $this->clean($dbName); $this->clean($newName); + $this->clean($newOwner); + $this->clean($comment); - $status = $this->alterDatabaseRename($dbName, $newName); - if ($status != 0) return -3; + $status = $this->beginTransaction(); + if ($status != 0) { + $this->rollbackTransaction(); + return -1; + } + + if ($dbName != $newName) { + $status = $this->alterDatabaseRename($dbName, $newName); + if ($status != 0) { + $this->rollbackTransaction(); + return -3; + } + } + + $status = $this->alterDatabaseOwner($newName, $newOwner); + if ($status != 0) { + $this->rollbackTransaction(); + return -2; + } if (trim($comment) != '' ) { - $status = $this->setComment('DATABASE',$dbName,'', $comment); - if ($status != 0) return -4; + $status = $this->setComment('DATABASE', $dbName, '', $comment); + if ($status != 0) { + $this->rollbackTransaction(); + return -4; + } } - else return 0; + return $this->endTransaction(); } /** -- 2.39.5