Rename function also for PostgreSQL 7.2 and 7.3 .
authorsoranzo <soranzo>
Thu, 15 Jul 2004 10:59:55 +0000 (10:59 +0000)
committersoranzo <soranzo>
Thu, 15 Jul 2004 10:59:55 +0000 (10:59 +0000)
classes/database/Postgres.php
classes/database/Postgres72.php
classes/database/Postgres73.php
classes/database/Postgres74.php

index cdd0cbe3f969b8ec7503e16ec9dcc82a3d344109..170ff4891d180ec661296557a2dba9f83447b131 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.237 2004/07/14 19:09:38 soranzo Exp $
+ * $Id: Postgres.php,v 1.238 2004/07/15 10:59:55 soranzo Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -3897,7 +3897,6 @@ class Postgres extends BaseDB {
        function hasIndicies() { return true; }
        function hasLanguages() { return true; }
        function hasOpClasses() { return true; }
-       function hasFunctionRename() { return true; }
 
 }
 
index 48393cd76f82020f6432c16664f540fa7a0de717..26d682d9b73ac045c4af87e6671b39f72b8d6412 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres72.php,v 1.73 2004/07/14 18:32:02 soranzo Exp $
+ * $Id: Postgres72.php,v 1.74 2004/07/15 10:59:55 soranzo Exp $
  */
 
 
@@ -337,8 +337,9 @@ class Postgres72 extends Postgres71 {
         * @param $comment The comment on the function   
         * @return 0 success
         * @return -1 transaction error
-        * @return -2 commenting error
-        * @return -3 rename error
+        * @return -2 drop function error
+        * @return -3 create function error
+        * @return -4 comment error
         */
        function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $comment) {
                // Begin a transaction
@@ -349,30 +350,33 @@ class Postgres72 extends Postgres71 {
                }
 
                // Replace the existing function
-               $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
-               if ($status != 0) {
-                       $this->rollbackTransaction();
-                       return -1;
+               if ($funcname != $newname) {
+                       $status = $this->dropFunction($function_oid, false);
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
+                               return -2;
+                       }
+
+                       $status = $this->createFunction($newname, $args, $returns, $definition, $language, $flags, $setof, false);
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
+                               return -3;
+                       }
+               } else {
+                       $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
+                               return -3;
+                       }
                }
 
                // Comment on the function
-               $this->fieldClean($funcname);
+               $this->fieldClean($newname);
                $this->clean($comment);
-               $status = $this->setComment('FUNCTION', "\"{$funcname}\"({$args})", null, $comment);
+               $status = $this->setComment('FUNCTION', "\"{$newname}\"({$args})", null, $comment);
                if ($status != 0) {
                        $this->rollbackTransaction();
-                       return -2;
-               }
-
-               // Rename the function, if necessary
-               $this->fieldClean($newname);
-               if ($funcname != $newname && $this->hasFunctionRename()) {
-                       $sql = "ALTER FUNCTION \"{$funcname}\"({$args}) RENAME TO \"{$newname}\"";
-                       $status = $this->execute($sql);
-                       if ($status != 0) {
-                               $this->rollbackTransaction();
-                               return -3;
-                       }
+                       return -4;
                }
                
                return $this->endTransaction();
index ab84b8a9e76ac709556f52d2a7ac4a49efb03201..cc54624d10a2bb23cf5b9e105e76e6714dd84cee 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.130 2004/07/15 09:35:30 jollytoad Exp $
+ * $Id: Postgres73.php,v 1.131 2004/07/15 10:59:55 soranzo Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1685,7 +1685,6 @@ class Postgres73 extends Postgres72 {
        function hasUserSessionDefaults() { return true; }
        function hasVariables() { return true; }
        function hasFullExplain() { return true; }
-       function hasFunctionRename() { return false; }
        function hasForeignKeysInfo() { return true; }
        function hasViewColumnRename() { return true; }
 
index 899ac360792da17c9b51170ed9c26cec735e2eb7..b25bcacf832227ac23f8f9f51d1aef40948352e1 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.37 2004/07/14 14:52:18 jollytoad Exp $
+ * $Id: Postgres74.php,v 1.38 2004/07/15 10:59:55 soranzo Exp $
  */
 
 include_once('./classes/database/Postgres73.php');
@@ -374,6 +374,8 @@ class Postgres74 extends Postgres73 {
                return $this->endTransaction();
        }       
 
+       // User functions
+
        /**
         * Renames a user
         * @param $username The username of the user to rename
@@ -423,11 +425,68 @@ class Postgres74 extends Postgres73 {
                return $this->endTransaction();
        }
 
+       // Function functions
+
+       /**
+        * Updates (replaces) a function.
+        * @param $function_oid The OID of the function
+        * @param $funcname The name of the function to create
+        * @param $newname The new name for the function
+        * @param $args The array of argument types
+        * @param $returns The return type
+        * @param $definition The definition for the new function
+        * @param $language The language the function is written for
+        * @param $flags An array of optional flags
+        * @param $setof True if returns a set, false otherwise
+        * @param $comment The comment on the function   
+        * @return 0 success
+        * @return -1 transaction error
+        * @return -3 create function error
+        * @return -4 comment error
+        * @return -5 rename function error
+        */
+       function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $comment) {
+               // Begin a transaction
+               $status = $this->beginTransaction();
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -1;
+               }
+
+               // Replace the existing function
+               $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -3;
+               }
+
+               // Comment on the function
+               $this->fieldClean($funcname);
+               $this->clean($comment);
+               $status = $this->setComment('FUNCTION', "\"{$funcname}\"({$args})", null, $comment);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -4;
+               }
+
+               // Rename the function, if necessary
+               $this->fieldClean($newname);
+               if ($funcname != $newname) {
+                       $sql = "ALTER FUNCTION \"{$funcname}\"({$args}) RENAME TO \"{$newname}\"";
+                       $status = $this->execute($sql);
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
+                               return -5;
+                       }
+               }
+               
+               return $this->endTransaction();
+       }
+
        // Capabilities
        function hasGrantOption() { return true; }
        function hasDomainConstraints() { return true; }
        function hasUserRename() { return true; }
-       function hasFunctionRename() { return true; }
        function hasSchemaDump() { return true; }
        function hasRecluster() { return true; }