don't change owner name if owner name wasn't changed. allows owners to alter tables...
authorchriskl <chriskl>
Fri, 6 Feb 2004 01:48:16 +0000 (01:48 +0000)
committerchriskl <chriskl>
Fri, 6 Feb 2004 01:48:16 +0000 (01:48 +0000)
BUGS
classes/database/Postgres.php

diff --git a/BUGS b/BUGS
index d6336220ea0fd1a9e16a4aad95cb1281fbc63c33..beb3646071898b56cc8092892962ed8f6f476d8a 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -20,4 +20,6 @@ Need to fix:
   pretty type name and schema support
 * Report login errors
 * Edit Query
+* Don't offer owner change feature if user is not superuser
+
 
index 98d3bceb46fa2dcaedec30f3ed848547898912fa..f405cdf8010be7401bcf9f28b57cf9db34f75872 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.180 2004/02/02 12:15:58 chriskl Exp $
+ * $Id: Postgres.php,v 1.181 2004/02/06 01:48:16 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1184,6 +1184,7 @@ class Postgres extends BaseDB {
         * @return -2 owner error
         * @return -3 rename error
         * @return -4 comment error
+        * @return -5 get existing owner error
         */
        function alterTable($table, $name, $owner, $comment) {
                $this->fieldClean($table);
@@ -1210,12 +1211,24 @@ class Postgres extends BaseDB {
                
                // Owner
                if ($this->hasAlterTableOwner() && $owner != '') {
-                       $sql = "ALTER TABLE \"{$table}\" OWNER TO \"{$owner}\"";
-       
-                       $status = $this->execute($sql);
-                       if ($status != 0) {
+                       // Fetch existing owner
+                       $data = &$this->getTable($table);
+                       if ($data->recordCount() != 1) {
                                $this->rollbackTransaction();
-                               return -2;
+                               return -5;
+                       }
+                               
+                       // If owner has been changed, then do the alteration.  We are
+                       // careful to avoid this generally as changing owner is a
+                       // superuser only function.
+                       if ($data->f[$this->tbFields['tbowner']] != $owner) {
+                               $sql = "ALTER TABLE \"{$table}\" OWNER TO \"{$owner}\"";
+               
+                               $status = $this->execute($sql);
+                               if ($status != 0) {
+                                       $this->rollbackTransaction();
+                                       return -2;
+                               }
                        }
                }