add alter function owner, schema. thanks go to ioguix for some pointers. needs testin...
authorxzilla <xzilla>
Thu, 15 Nov 2007 23:09:21 +0000 (23:09 +0000)
committerxzilla <xzilla>
Thu, 15 Nov 2007 23:09:21 +0000 (23:09 +0000)
HISTORY
TODO
classes/database/Postgres.php
classes/database/Postgres74.php
classes/database/Postgres80.php
classes/database/Postgres81.php
functions.php

diff --git a/HISTORY b/HISTORY
index 0376e0be627fe5ed819ce6c07b05ab45556c1a2c..49f3a948b697377ed9eab3eefc3d48bca6d07da5 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -20,6 +20,7 @@ Features
   properties page (ioguix)
 * Add Support for Enum type creation (ioguix,xzilla)
 * Add alter name, owner, comment and properties for sequences (ioguix)
+* Add function costing options
 
 Bugs
 * Fix inability to assign a field type/domain of a different schema
diff --git a/TODO b/TODO
index 7dcabeb29faba5bf5ea802247ef0dddbf2d65845..500bb4549afc4a1977f43625e3bd4fab62239398 100644 (file)
--- a/TODO
+++ b/TODO
@@ -113,6 +113,7 @@ Functions
 * Display owner
 * Alter owner
 * Alter schema 
+* GUC settings [8.3]
 
 Indexes 
 -------
index 8ad6dd7e5f9ac732422a66ef615b37e0d5c87ab2..0c718adaf3deef21b2808275f11cb53a49adeed6 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.309 2007/11/15 06:06:45 xzilla Exp $
+ * $Id: Postgres.php,v 1.310 2007/11/15 23:09:21 xzilla Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -4846,6 +4846,8 @@ class Postgres extends ADODB_base {
        function hasVirtualTransactionId() {return false;}
        function hasFunctionCosting() {return false;}
        function hasFunctionGUC() {return false;}
+        function hasFunctionAlterSchema() { return false; }
+        function hasFunctionAlterOwner() { return false; }
 }
 
 ?>
index 028080ec7dd1006a155cff963653ebd070b10b59..14c609d997e70f5037b0a11fb675c90b53f95a4f 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.65 2007/11/15 06:06:45 xzilla Exp $
+ * $Id: Postgres74.php,v 1.66 2007/11/15 23:09:21 xzilla Exp $
  */
 
 include_once('./classes/database/Postgres73.php');
@@ -565,8 +565,10 @@ class Postgres74 extends Postgres73 {
         * @return -3 create function error
         * @return -4 comment error
         * @return -5 rename function error
+        * @return -6 alter owner error
+        * @return -7 alter schema error
         */
-       function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment) {
+       function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $funcown, $newown, $funcschema, $newschema, $cost, $rows, $comment) {
                // Begin a transaction
                $status = $this->beginTransaction();
                if ($status != 0) {
@@ -599,8 +601,39 @@ class Postgres74 extends Postgres73 {
                                $this->rollbackTransaction();
                                return -5;
                        }
+
+                        $funcname = $newname; 
                }
 
+                // Alter the owner, if necessary
+                if ($this->hasFunctionAlterOwner()) {
+               $this->fieldClean($newown);
+                   if ($funcown != $newown) {
+                       $sql = "ALTER FUNCTION \"{$funcname}\"({$args}) OWNER TO \"{$newown}\"";
+                       $status = $this->execute($sql);
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
+                               return -6;
+                       }
+                   }   
+
+                }
+
+                // Alter the schema, if necessary
+                if ($this->hasFunctionAlterSchema()) {
+                   $this->fieldClean($newschema);
+                   if ($funcschema != $newschema) {
+                       $sql = "ALTER FUNCTION \"{$funcname}\"({$args}) SET SCHEMA \"{$newschema}\"";
+                       $status = $this->execute($sql);
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
+                               return -7;
+                       }
+                   }
+
+                }
+
+
                return $this->endTransaction();
        }
 
index db1d09e82aa79155a7debf5c9b65ae8f64d0feee..9a39030738c7300d74a157028e40166734309095 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * PostgreSQL 8.0 support
  *
- * $Id: Postgres80.php,v 1.24 2007/10/02 21:44:35 ioguix Exp $
+ * $Id: Postgres80.php,v 1.25 2007/11/15 23:09:21 xzilla Exp $
  */
 
 include_once('./classes/database/Postgres74.php');
@@ -511,6 +511,8 @@ class Postgres80 extends Postgres74 {
                $sql = "SELECT 
                                        pc.oid AS prooid,
                                        proname,
+                                       pg_catalog.pg_get_userbyid(proowner) AS proowner,
+                                        nspname as proschema, 
                                        lanname as prolanguage,
                                        pg_catalog.format_type(prorettype, NULL) as proresult,
                                        prosrc,
@@ -523,10 +525,13 @@ class Postgres80 extends Postgres74 {
                                        proargnames AS proargnames,
                                        pg_catalog.obj_description(pc.oid, 'pg_proc') AS procomment
                                FROM
-                                       pg_catalog.pg_proc pc, pg_catalog.pg_language pl
+                                       pg_catalog.pg_proc pc, pg_catalog.pg_language pl, pg_catalog.pg_namespace pn
                                WHERE 
                                        pc.oid = '{$function_oid}'::oid
-                               AND pc.prolang = pl.oid
+                                       AND 
+                                        pc.prolang = pl.oid
+                                        AND
+                                        pc.pronamespace = pn.oid 
                                ";
        
                return $this->selectSet($sql);
@@ -538,6 +543,7 @@ class Postgres80 extends Postgres74 {
        function hasTablespaces() { return true; }
        function hasSignals() { return true; }
        function hasNamedParams() { return true; }
+        function hasFunctionAlterOwner() { return true; }
        
 }
 
index 15fadcace13b63b9cb16e8597b0d87da423d467d..6b78987f995fa9a5b30f6d2334d8400d64d997b6 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * PostgreSQL 8.1 support
  *
- * $Id: Postgres81.php,v 1.14 2006/12/31 19:04:05 xzilla Exp $
+ * $Id: Postgres81.php,v 1.15 2007/11/15 23:09:21 xzilla Exp $
  */
 
 include_once('./classes/database/Postgres80.php');
@@ -501,6 +501,7 @@ class Postgres81 extends Postgres80 {
        function hasAutovacuum() { return true; }
        function hasPreparedXacts() { return true; }
        function hasDisableTriggers() { return true; }
+        function hasFunctionAlterSchema() { return true; }
 }
 
 ?>
index 0bcde67f48d362ec2be1315e790fe56b7c0c6e33..e3cfb0db8f91ae9d7e95c6bdcd5b7dd0c736b8a0 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage functions in a database
         *
-        * $Id: functions.php,v 1.71 2007/11/15 17:13:16 xzilla Exp $
+        * $Id: functions.php,v 1.72 2007/11/15 23:09:21 xzilla Exp $
         */
 
        // Include application functions
@@ -16,7 +16,8 @@
         * Function to save after editing a function
         */
        function doSaveEdit() {
-               global $data, $lang;
+               global $data, $lang; 
+                global $misc, $_reload_browser;
                
                $fnlang = strtolower($_POST['original_lang']);
                
                                                                                $_POST['original_arguments'], 
                                                                                $_POST['original_returns'], $def,
                                                                                $_POST['original_lang'], $_POST['formProperties'], 
-                                                                               isset($_POST['original_setof']), 
+                                                                               isset($_POST['original_setof']),
+                                                                                $_POST['original_owner'],  $_POST['formFuncOwn'], 
+                                                                                $_POST['original_schema'],  $_POST['formFuncSchema'], 
                                                                                 isset($_POST['formCost']) ? $_POST['formCost'] : null, 
                                                                                isset($_POST['formRows']) ? $_POST['formRows'] : 0, $_POST['formComment']);
-               if ($status == 0)
+               if ($status == 0) {
+                       // If function has had schema altered, need to change to the new schema 
+                       // and reload the browser frame.
+                       if ($_POST['formFuncSchema'] != $_POST['original_schema']) {
+                           // Jump them to the new function schema 
+                           $_REQUEST['schema'] = $_POST['formFuncSchema'];
+                           $misc->href = "server={$_REQUEST['server']}&amp;database={$_REQUEST['database']}&amp;schema={$_REQUEST['schema']}";
+                           // Force a browser reload
+                           $_reload_browser = true;
+                        }
                        doProperties($lang['strfunctionupdated']);
-               else
+               } else {
                        doEdit($lang['strfunctionupdatedbad']);
+                }
        }
        
        /**
@@ -63,6 +76,8 @@
                        if (!isset($_POST['formComment'])) $_POST['formComment'] = $fndata->fields['procomment'];
                        if (!isset($_POST['formObjectFile'])) $_POST['formObjectFile'] = $fndata->fields['probin'];
                        if (!isset($_POST['formLinkSymbol'])) $_POST['formLinkSymbol'] = $fndata->fields['prosrc'];
+                       if (!isset($_POST['formFuncOwn'])) $_POST['formFuncOwn'] = $fndata->fields['proowner'];
+                       if (!isset($_POST['formFuncSchema'])) $_POST['formFuncSchema'] = $fndata->fields['proschema'];
 
                        if ($data->hasFunctionCosting()) {
                                if (!isset($_POST['formCost'])) $_POST['formCost'] = $fndata->fields['procost'];
                        echo "<form action=\"functions.php\" method=\"post\">\n";
                        echo "<table style=\"width: 90%\">\n";
                        echo "<tr>\n";
+                       echo "<th class=\"data required\">{$lang['strschema']}</th>\n";
                        echo "<th class=\"data required\">{$lang['strfunction']}</th>\n";
                        echo "<th class=\"data\">{$lang['strarguments']}</th>\n";
                        echo "<th class=\"data required\">{$lang['strreturns']}</th>\n";
                        echo "<th class=\"data required\">{$lang['strproglanguage']}</th>\n";
                        echo "</tr>\n";
-                               
+
                        echo "<tr>\n";
                        echo "<td class=\"data1\">";
+                       echo "<input type=\"hidden\" name=\"original_schema\" value=\"", htmlspecialchars($fndata->fields['proschema']),"\" />\n"; 
+                        if ($data->hasFunctionAlterSchema()) {
+                            $schemas = $data->getSchemas();
+                            echo "<select name=\"formFuncSchema\">";
+                               while (!$schemas->EOF) {
+                                       $schema = $schemas->fields['nspname'];
+                                       echo "<option value=\"", htmlspecialchars($schema), "\"",
+                                               ($schema == $_POST['formFuncSchema']) ? ' selected="selected"' : '', ">", htmlspecialchars($schema), "</option>\n";
+                                       $schemas->moveNext();
+                               }
+                           echo "</select>\n";
+                        }
+                       echo "</td>\n";
+                       echo "<td class=\"data1\">";
                        echo "<input type=\"hidden\" name=\"original_function\" value=\"", htmlspecialchars($fndata->fields['proname']),"\" />\n"; 
                        echo "<input name=\"formFunction\" style=\"width: 100%\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['formFunction']), "\" />";
                        echo "</td>\n";
                                echo "<td class=\"data1\" colspan=\"2\"><input type=\"text\" name=\"formLinkSymbol\" style=\"width:100%\" value=\"",
                                        htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n";
                        } else if ($fnlang == 'internal') {
-                               echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strlinksymbol']}</th></tr>\n";
-                               echo "<tr><td class=\"data1\" colspan=\"4\"><input type=\"text\" name=\"formLinkSymbol\" style=\"width:100%\" value=\"",
+                               echo "<tr><th class=\"data\" colspan=\"5\">{$lang['strlinksymbol']}</th></tr>\n";
+                               echo "<tr><td class=\"data1\" colspan=\"5\"><input type=\"text\" name=\"formLinkSymbol\" style=\"width:100%\" value=\"",
                                        htmlspecialchars($_POST['formLinkSymbol']), "\" /></td></tr>\n";
                        } else {
-                               echo "<tr><th class=\"data required\" colspan=\"4\">{$lang['strdefinition']}</th></tr>\n";
-                               echo "<tr><td class=\"data1\" colspan=\"4\"><textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\">", 
+                               echo "<tr><th class=\"data required\" colspan=\"5\">{$lang['strdefinition']}</th></tr>\n";
+                               echo "<tr><td class=\"data1\" colspan=\"5\"><textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\">", 
                                        htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";
                        }
                        
                        // Display function comment
-                       echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strcomment']}</th></tr>\n";
-                       echo "<tr><td class=\"data1\" colspan=\"4\"><textarea style=\"width:100%;\" name=\"formComment\" rows=\"3\" cols=\"50\">", 
+                       echo "<tr><th class=\"data\" colspan=\"5\">{$lang['strcomment']}</th></tr>\n";
+                       echo "<tr><td class=\"data1\" colspan=\"5\"><textarea style=\"width:100%;\" name=\"formComment\" rows=\"3\" cols=\"50\">", 
                                        htmlspecialchars($_POST['formComment']), "</textarea></td></tr>\n";
 
                        // Display function cost options
                        if ($data->hasFunctionCosting()) {
-                               echo "<tr><th class=\"data required\" colspan=\"4\">{$lang['strfunctioncosting']}</th></tr>\n";
+                               echo "<tr><th class=\"data required\" colspan=\"5\">{$lang['strfunctioncosting']}</th></tr>\n";
                                echo "<td class=\"data1\" colspan=\"2\">{$lang['strexecutioncost']}: <input name=\"formCost\" size=\"16\" value=\"".
                                        htmlspecialchars($_POST['formCost']) ."\" /></td>";
                                echo "<td class=\"data1\" colspan=\"2\">{$lang['strresultrows']}: <input name=\"formRows\" size=\"16\" value=\"",
 
                        // Display function properties
                        if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) {
-                               echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strproperties']}</th></tr>\n";
-                               echo "<tr><td class=\"data1\" colspan=\"4\">\n";
+                               echo "<tr><th class=\"data\" colspan=\"5\">{$lang['strproperties']}</th></tr>\n";
+                               echo "<tr><td class=\"data1\" colspan=\"5\">\n";
                                $i = 0;
                                foreach ($data->funcprops as $k => $v) {
                                        echo "<select name=\"formProperties[{$i}]\">\n";
                                }
                                echo "</td></tr>\n";
                        }               
+
+                        // function owner
+                        if ($data->hasFunctionAlterOwner()) {
+                           $users = $data->getUsers();
+                            echo "<td class=\"data1\" colspan=\"5\">{$lang['strowner']}: <select name=\"formFuncOwn\">";
+                               while (!$users->EOF) {
+                                       $uname = $users->fields['usename'];
+                                       echo "<option value=\"", htmlspecialchars($uname), "\"",
+                                               ($uname == $_POST['formFuncOwn']) ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n";
+                                       $users->moveNext();
+                               }
+                               echo "</select>\n";
+                           echo "<input type=\"hidden\" name=\"original_owner\" value=\"", htmlspecialchars($fndata->fields['proowner']),"\" />\n"; 
+                            echo "</td></tr>\n";                               
+                        }
                        echo "</table>\n";
                        echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
                        echo "<input type=\"hidden\" name=\"function\" value=\"", htmlspecialchars($_REQUEST['function']), "\" />\n";
                                }
                                echo "</td></tr>\n";
                        }               
+
+                        echo "<td class=\"data1\" colspan=\"5\">{$lang['strowner']}: ", htmlspecialchars($funcdata->fields['proowner']),"\n"; 
+                        echo "</td></tr>\n";                           
                        echo "</table>\n";
                }
                else echo "<p>{$lang['strnodata']}</p>\n";