Fix alterView, update TODO & HISTORY
authorioguix <ioguix>
Wed, 12 Dec 2007 10:45:35 +0000 (10:45 +0000)
committerioguix <ioguix>
Wed, 12 Dec 2007 10:45:35 +0000 (10:45 +0000)
HISTORY
TODO
classes/database/Postgres73.php
classes/database/Postgres81.php

diff --git a/HISTORY b/HISTORY
index c3b0fa7107b65e08c8fbc149ecf464f823a73c4a..f131df3c4a773ead2a34e2884852c37ee89d1388 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -23,8 +23,7 @@ Features
 * Add function costing options (xzilla)
 * Add alter owner & schema on function (xzilla)
 * Add a popup window for the session requests history (karl, ioguix)
-* Add alter table schema (ioguix)
-* Add alter sequence schema (ioguix)
+* Add alter table, view, sequence schema (ioguix)
 
 Bugs
 * Fix inability to assign a field type/domain of a different schema
@@ -32,6 +31,8 @@ Bugs
 * Fix PHP5 Strict mode complaints 
 * Fix IN/NOT IN to accept text input lists 'a','b'
 * Fix bytea doesn't display as NULL when NULL
+* Schema qualifing every object to avoid non wanted behaviour about users' rights
+  and schema_path
 
 Translations
 * utf traditional chinese (Kuo Chaoyi)
diff --git a/TODO b/TODO
index 87a8bedae5f6b3c0723a0c85720397caf2a0e621..2844c708f0f454dc01d177d3fb502f1c4708b22d 100644 (file)
--- a/TODO
+++ b/TODO
@@ -67,7 +67,7 @@ Schemas (7.3)
 
 * -Rename (xzilla)
 * -Alter owner (ioguix)
-* Alter ... SET SCHEMA support per 8.1
+* Alter ... SET SCHEMA support per 8.1 
 
 
 Large Objects
@@ -98,7 +98,7 @@ Views
 
 * Support temporary views per 8.1?
 * Allow INSERT and import on views with the appropriate rules.
-* - Allow altering of comments (ioguix, with rename & owner)
+* - Allow altering of comments (ioguix, with rename, owner & schema)
 
 
 Sequences
index ae054877be42e1d29b1ad97ac36ad30c0a242f45..21d14ad97fb45d3bfe30f16696cb3052259e98a4 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres73.php,v 1.181 2007/12/12 04:11:10 xzilla Exp $
+ * $Id: Postgres73.php,v 1.182 2007/12/12 10:45:35 ioguix Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -859,70 +859,47 @@ class Postgres73 extends Postgres72 {
        }
 
         /**
-         * Alters a view
-         * @param $view The name of the view
+         * Protected method which alter a view
+         * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION
+         * @param $vwrs The view recordSet returned by getView()
          * @param $name The new name for the view
          * @param $owner The new owner for the view
          * @param $comment The comment on the view
          * @return 0 success
-         * @return -1 transaction error
-         * @return -2 owner error
          * @return -3 rename error
          * @return -4 comment error
-         * @return -5 get existing view error
+         * @return -5 owner error
+         * @return -6 schema error
          */
-    function alterView($view, $name, $owner, $comment) {
-               $this->fieldClean($view);
-               $this->fieldClean($name);
-               $this->fieldClean($owner);
-               $this->clean($comment);
+        /*protected*/
+    function _alterView($vwrs, $name, $owner, $schema, $comment) {
 
-               $status = $this->beginTransaction();
-               if ($status != 0) {
-                       $this->rollbackTransaction();
-                       return -1;
-               }
+               $view = $vwrs->fields['relname'];
 
                // Comment
-               $status = $this->setComment('VIEW', $view, '', $comment);
-               if ($status != 0) {
-                       $this->rollbackTransaction();
+               $this->clean($comment);
+               if ($this->setComment('VIEW', $view, '', $comment) != 0)
                        return -4;
-               }
 
                // Owner
-               if ($this->hasAlterTableOwner() && $owner != '') {
-                       // Fetch existing owner
-                       $data = $this->getView($view);
-                       if ($data->recordCount() != 1) {
-                               $this->rollbackTransaction();
-                               return -5;
-                       }
-
+               $this->fieldClean($owner);
+               if ((!empty($owner)) && ($vwrs->fields['relowner'] != $owner)) {
                        // 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->fields['relowner'] != $owner) {
-                               $sql = "ALTER TABLE \"{$this->_schema}\".\"{$view}\" OWNER TO \"{$owner}\"";
-                               $status = $this->execute($sql);
-                               if ($status != 0) {
-                                       $this->rollbackTransaction();
-                                       return -2;
-                               }
-                       }
+                       $sql = "ALTER TABLE \"{$this->_schema}\".\"{$view}\" OWNER TO \"{$owner}\"";
+                       $status = $this->execute($sql);
+                       if ($status != 0) return -5;
                }
-
+               
                // Rename (only if name has changed)
+               $this->fieldClean($name);
                if ($name != $view) {
-                       $sql = "ALTER TABLE \"{$this->_schema}\".\"{$view}\" RENAME TO \"{$name}\"";
-                       $status = $this->execute($sql);
-                       if ($status != 0) {
-                               $this->rollbackTransaction();
+                       if ($this->renameView($view, $name) != 0)
                                return -3;
-                       }
                }
 
-               return $this->endTransaction();
+               return 0;
        }
 
        /**
@@ -965,8 +942,25 @@ class Postgres73 extends Postgres72 {
         * @return -3 create view error
         */
        function setView($viewname, $definition,$comment) {
-                return $this->createView($viewname, $definition, true, $comment);
+               return $this->createView($viewname, $definition, true, $comment);
        }
+       
+       /**
+        * Rename a view
+        * @param $view The current view's name
+        * @param $name The new view's name
+        * @return -1 Failed
+        * @return 0 success
+        */
+       function renameView($view, $name) {
+               $this->fieldClean($name);
+               $this->fieldClean($view);
+               $sql = "ALTER TABLE \"{$this->_schema}\".\"{$view}\" RENAME TO \"{$name}\"";
+               if ($this->execute($sql) != 0)
+                       return -1;
+               return 0;
+       }
+
 
        // Sequence functions
 
index 339f8ea470a48a1503c523605465b6e3edce0bd8..29881e06016e8696468f55bac1147b093d9c919a 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * PostgreSQL 8.1 support
  *
- * $Id: Postgres81.php,v 1.19 2007/12/12 04:11:10 xzilla Exp $
+ * $Id: Postgres81.php,v 1.20 2007/12/12 10:45:35 ioguix Exp $
  */
 
 include_once('./classes/database/Postgres80.php');
@@ -555,6 +555,7 @@ class Postgres81 extends Postgres80 {
          * @return -5 owner error
          * @return -6 schema error
          */
+       /*protected*/
     function _alterView($vwrs, $name, $owner, $schema, $comment) {
 
                $status = parent::_alterView($vwrs, $name, $owner, $schema, $comment);
@@ -571,7 +572,7 @@ class Postgres81 extends Postgres80 {
 
                        // If tablespace has been changed, then do the alteration.  We
                        // don't want to do this unnecessarily.
-                       $sql = "ALTER TABLE \"{$view}\" SET SCHEMA \"{$schema}\"";
+                       $sql = "ALTER TABLE \"{$this->_schema}\".\"{$view}\" SET SCHEMA \"{$schema}\"";
 
                        $status = $this->execute($sql);
                        if ($status != 0) return -6;