Drop CASCADE for functions. Move some class functions around.
authorchriskl <chriskl>
Wed, 30 Apr 2003 06:49:11 +0000 (06:49 +0000)
committerchriskl <chriskl>
Wed, 30 Apr 2003 06:49:11 +0000 (06:49 +0000)
classes/database/Postgres.php
classes/database/Postgres71.php
classes/database/Postgres72.php
functions.php

index 642363f5de9e60ed83912a96d45a9e0a6186ae01..9c34f0a2e7e0414503550ea2304a57a8948a558d 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.81 2003/04/30 06:35:41 chriskl Exp $
+ * $Id: Postgres.php,v 1.82 2003/04/30 06:49:11 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -2104,7 +2104,120 @@ class Postgres extends BaseDB {
                return $this->selectSet($sql);
        }
 
-               // Type conversion routines
+       // Function functions
+
+       /**
+        * Returns a list of all functions that can be used in triggers
+        */
+       function &getTriggerFunctions() {
+               return $this->getFunctions(true);
+       }
+
+       /**
+        * Updates a function.  Postgres 7.1 doesn't have CREATE OR REPLACE function,
+        * so we do it with a drop and a recreate.
+        * @param $funcname The name of the function to update
+        * @param $definition The new definition for the function
+        * @return 0 success
+        * @return -1 transaction error
+        * @return -2 drop function error
+        * @return -3 create function error
+        */
+       function setFunction($funcname, $definition) {
+               $status = $this->beginTransaction();
+               if ($status != 0) return -1;
+
+               $status = $this->dropFunction($funcname);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -2;
+               }
+               
+               $status = $this->createFunction($funcname, $definition);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -3;
+               }
+
+               $status = $this->endTransaction();
+               return ($status == 0) ? 0 : -1;
+       }
+       
+       /**
+        * Creates a new function.
+        * @param $funcname The name of the function to create
+        * @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 $replace (optional) True if OR REPLACE, false for normal
+        * @return 0 success
+        */
+       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $replace = false) {
+               /*
+               RE: arguments implementation It seem to me that we should be  getting passed a comma delimited string
+               and that we need a comma delimited string
+               So why go through the array end around 
+               ADODB throws errors if you leave it blank, and join complaines as well
+               
+
+               Also I'm dropping support for the WITH option for now
+               Given that there are only 3 options, this might best be implemented with hardcoding
+               */
+
+               $this->clean($funcname);
+//             if (is_array($args)) {
+//                     $this->arrayClean($args);
+//             }
+               $this->clean($args);
+               $this->clean($returns);
+               $this->clean($definition);
+               $this->clean($language);
+//             if (is_array($flags)) {
+//                     $this->arrayClean($flags);
+//             }
+
+               $sql = "CREATE";
+               if ($replace) $sql .= " OR REPLACE";
+               $sql .= " FUNCTION \"{$funcname}\" (";
+/*
+               if (sizeof($args) > 0)
+                       $sql .= '"' . join('", "', $args) . '"';
+*/
+               if ($args)
+                       $sql .= $args;
+
+               // For some reason, the returns field cannot have quotes...
+               $sql .= ") RETURNS {$returns} AS '\n";
+               $sql .= $definition;
+               $sql .= "\n'";
+               $sql .= " LANGUAGE \"{$language}\"";
+/*
+               if (sizeof($flags) > 0)
+                       $sql .= ' WITH ("' . join('", "', $flags) . '")';
+*/
+
+
+               return $this->execute($sql);
+       }
+               
+       /**
+        * Drops a function.
+        * @param $funcname The name of the function to drop
+        * @param $cascade True to cascade drop, false to restrict
+        * @return 0 success
+        */
+       function dropFunction($funcname, $cascade) {
+               $this->clean($funcname);
+       
+               $sql = "DROP FUNCTION {$funcname} ";
+               if ($cascade) $sql .= " CASCADE";
+               
+               return $this->execute($sql);
+       }       
+
+       // Type conversion routines
 
        /**
         * Change the value of a parameter to 't' or 'f' depending on whether it evaluates to true or false
index 12cbe46e467feabfd7ab4bffba2609442e1a0aba..401ee90d93da77d7c9b76a48620f6fd5dc72e630 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres71.php,v 1.29 2003/03/27 12:56:30 chriskl Exp $
+ * $Id: Postgres71.php,v 1.30 2003/04/30 06:49:12 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -90,43 +90,6 @@ class Postgres71 extends Postgres {
                return $this->selectSet($sql);
        }
 
-       /**
-        * Returns a list of all functions that can be used in triggers
-        */
-       function &getTriggerFunctions() {
-               return $this->getFunctions(true);
-       }
-
-       /**
-        * Updates a function.  Postgres 7.1 doesn't have CREATE OR REPLACE function,
-        * so we do it with a drop and a recreate.
-        * @param $funcname The name of the function to update
-        * @param $definition The new definition for the function
-        * @return 0 success
-        * @return -1 transaction error
-        * @return -2 drop function error
-        * @return -3 create function error
-        */
-       function setFunction($funcname, $definition) {
-               $status = $this->beginTransaction();
-               if ($status != 0) return -1;
-
-               $status = $this->dropFunction($funcname);
-               if ($status != 0) {
-                       $this->rollbackTransaction();
-                       return -2;
-               }
-               
-               $status = $this->createFunction($funcname, $definition);
-               if ($status != 0) {
-                       $this->rollbackTransaction();
-                       return -3;
-               }
-
-               $status = $this->endTransaction();
-               return ($status == 0) ? 0 : -1;
-       }
-
        /**
         * Return all information relating to a table
         * @param $table The name of the table
index 122b6af9de95a7818278c4bf46fdd0752570438b..de085795174a476a5a96143d91cea003a2ba3b0b 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.35 2003/04/28 12:07:28 chriskl Exp $
+ * $Id: Postgres72.php,v 1.36 2003/04/30 06:49:12 chriskl Exp $
  */
 
 
@@ -232,78 +232,6 @@ class Postgres72 extends Postgres71 {
                                ";
        
                return $this->selectSet($sql);
-       }       
-
-       /**
-        * Creates a new function.
-        * @param $funcname The name of the function to create
-        * @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 $replace (optional) True if OR REPLACE, false for normal
-        * @return 0 success
-        */
-       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $replace = false) {
-               /*
-               RE: arguments implementation It seem to me that we should be  getting passed a comma delimited string
-               and that we need a comma delimited string
-               So why go through the array end around 
-               ADODB throws errors if you leave it blank, and join complaines as well
-               
-
-               Also I'm dropping support for the WITH option for now
-               Given that there are only 3 options, this might best be implemented with hardcoding
-               */
-
-               $this->clean($funcname);
-//             if (is_array($args)) {
-//                     $this->arrayClean($args);
-//             }
-               $this->clean($args);
-               $this->clean($returns);
-               $this->clean($definition);
-               $this->clean($language);
-//             if (is_array($flags)) {
-//                     $this->arrayClean($flags);
-//             }
-
-               $sql = "CREATE";
-               if ($replace) $sql .= " OR REPLACE";
-               $sql .= " FUNCTION \"{$funcname}\" (";
-/*
-               if (sizeof($args) > 0)
-                       $sql .= '"' . join('", "', $args) . '"';
-*/
-               if ($args)
-                       $sql .= $args;
-
-               // For some reason, the returns field cannot have quotes...
-               $sql .= ") RETURNS {$returns} AS '\n";
-               $sql .= $definition;
-               $sql .= "\n'";
-               $sql .= " LANGUAGE \"{$language}\"";
-/*
-               if (sizeof($flags) > 0)
-                       $sql .= ' WITH ("' . join('", "', $flags) . '")';
-*/
-
-
-               return $this->execute($sql);
-       }
-       
-       /**
-        * Drops a function.
-        * @param $funcname The name of the function to drop
-        * @return 0 success
-        */
-       function dropFunction($funcname) {
-               $this->clean($funcname);
-       
-               $sql = "DROP FUNCTION {$funcname} ";
-               
-               return $this->execute($sql);
        }
        
        /**
index b690e4564e177ada269c47d72c852c01301cafd0..8f26d22884af588e20e127ac0213264e4a3bab28 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage functions in a database
         *
-        * $Id: functions.php,v 1.9 2003/03/17 05:20:30 chriskl Exp $
+        * $Id: functions.php,v 1.10 2003/04/30 06:49:11 chriskl Exp $
         */
 
        // Include application functions
                        echo "<h2>", htmlspecialchars($_REQUEST['database']), ": {$lang['strfunctions']}: ", htmlspecialchars($_REQUEST['function']), ": {$lang['strdrop']}</h2>\n";
                        
                        echo "<p>", sprintf($lang['strconfdropfunction'], htmlspecialchars($_REQUEST['function'])), "</p>\n";   
+                       
                        echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
-                       echo "<input type=hidden name=action value=drop>\n";
-                       echo "<input type=hidden name=function value=\"", htmlspecialchars($_REQUEST['function']), "\">\n";
+                       echo "<input type=\"hidden\" name=\"action\" value=\"drop\">\n";
+                       echo "<input type=\"hidden\" name=\"function\" value=\"", htmlspecialchars($_REQUEST['function']), "\">\n";
                        echo $misc->form;
-                       echo "<input type=submit name=choice value=\"{$lang['stryes']}\"> <input type=submit name=choice value=\"{$lang['strno']}\">\n";
+                       // Show cascade drop option if supportd
+                       if ($localData->hasDropBehavior()) {
+                               echo "<p><input type=\"checkbox\" name=\"cascade\"> {$lang['strcascade']}</p>\n";
+                       }
+                       echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\"> <input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\">\n";
                        echo "</form>\n";
                }
                else {
-                       $status = $localData->dropFunction($_POST['function']);
+                       $status = $localData->dropFunction($_POST['function'], isset($_POST['cascade']));
                        if ($status == 0)
                                doDefault($lang['strfunctiondropped']);
                        else
                        doCreate();
                        break;
                case 'drop':
-                       if ($_POST['choice'] == "{$lang['stryes']}") doDrop(false);
+                       if (isset($_POST['yes'])) doDrop(false);
                        else doDefault();
                        break;
                case 'confirm_drop':