Bugfix: alterDatabase for 8.2 didn't use transactions and didn't change the owner.
authorsoranzo <soranzo>
Wed, 28 Mar 2007 18:52:34 +0000 (18:52 +0000)
committersoranzo <soranzo>
Wed, 28 Mar 2007 18:52:34 +0000 (18:52 +0000)
classes/database/Postgres74.php
classes/database/Postgres80.php
classes/database/Postgres82.php

index b15998bc0e64c34598ff160e1235f8642f60a4d2..83e469a0cce1268542e724ab206ec0dd6760a03e 100644 (file)
@@ -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);
                
index b1bb5e8fe115bf367ff4b8dfe7f5a4ac5401864f..77918358d59bf437019b8d49e064e61d7da14eee 100644 (file)
@@ -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
index 6f8fb10524a9cd7c50e3595e7e8e621ee0164732..0ef5664be6a3c48e4f239f4a45b3f0b5b3911383 100644 (file)
@@ -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();
        }
 
        /**