fix all operations on functions with spaces, etc.
authorchriskl <chriskl>
Sun, 1 Jun 2003 11:53:45 +0000 (11:53 +0000)
committerchriskl <chriskl>
Sun, 1 Jun 2003 11:53:45 +0000 (11:53 +0000)
BUGS
classes/database/Postgres.php
classes/database/Postgres72.php
functions.php
privileges.php

diff --git a/BUGS b/BUGS
index 5ad8133a0b28dd1cb13643691156d4196c2c6c44..df1678fe0f71afac50da03fd1f887e92464ed5df 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -1,4 +1,3 @@
 * Fix grant option/grantor stuff
 * First and last links in browse table
-* Can't grant/revoke on functions with spaces in them
 
index a991c6d5ccb747400e9512e5b6d1f77408a12be3..6a6b0490b8e768a8f8071811b36e7e2b34671a2b 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.117 2003/05/31 10:55:41 chriskl Exp $
+ * $Id: Postgres.php,v 1.118 2003/06/01 11:53:46 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -2046,7 +2046,6 @@ class Postgres extends BaseDB {
         * @return -4 invalid mode
         */
        function setPrivileges($mode, $type, $object, $public, $usernames, $groupnames, $privileges) {
-               $this->fieldClean($object);
                $this->fieldArrayClean($usernames);
                $this->fieldArrayClean($groupnames);
 
@@ -2060,26 +2059,29 @@ class Postgres extends BaseDB {
                        $sql = "{$mode} ALL PRIVILEGES ON";
                else
                        $sql = "{$mode} " . join(', ', $privileges) . " ON";
-               // @@ WE NEED SCHEMA SUPPORT BELOW
                switch ($type) {
                        case 'table':
                        case 'view':
                        case 'sequence':
+                               $this->fieldClean($object);
                                $sql .= " \"{$object}\"";
                                break;
                        case 'database':
+                               $this->fieldClean($object);
                                $sql .= " DATABASE \"{$object}\"";
                                break;
                        case 'function':
-                               // This is deliberately unquoted - $object is something like
-                               // "function(arg1, arg2)"
-                               $sql .= " FUNCTION {$object}";
+                               // Function comes in with $object as function OID
+                               $fn = &$this->getFunction($object);
+                               $this->fieldClean($fn->f[$this->fnFields['fnname']]);
+                               $sql .= " FUNCTION \"{$fn->f[$this->fnFields['fnname']]}\"({$fn->f[$this->fnFields['fnarguments']]})";
                                break;
                        case 'language':
+                               $this->fieldClean($object);
                                $sql .= " LANGUAGE \"{$object}\"";
                                break;
                        case 'schema':
-                               // @@ MOVE THIS TO 7.3 ONLY
+                               $this->fieldClean($object);
                                $sql .= " SCHEMA \"{$object}\"";
                                break;
                        default:
@@ -2328,6 +2330,7 @@ class Postgres extends BaseDB {
        /**
         * Updates a function.  Postgres 7.1 doesn't have CREATE OR REPLACE function,
         * so we do it with a drop and a recreate.
+        * @param $function_oid The OID of the function
         * @param $funcname The name of the function to create
         * @param $args The array of argument types
         * @param $returns The return type
@@ -2340,11 +2343,11 @@ class Postgres extends BaseDB {
         * @return -2 drop function error
         * @return -3 create function error
         */
-       function setFunction($funcname, $args, $returns, $definition, $language, $flags, $setof) {
+       function setFunction($function_oid, $funcname, $args, $returns, $definition, $language, $flags, $setof) {
                $status = $this->beginTransaction();
                if ($status != 0) return -1;
 
-               $status = $this->dropFunction("$funcname({$args})", false);
+               $status = $this->dropFunction($function_oid, false);
                if ($status != 0) {
                        $this->rollbackTransaction();
                        return -2;
@@ -2414,14 +2417,16 @@ class Postgres extends BaseDB {
                
        /**
         * Drops a function.
-        * @param $funcname The name of the function to drop
+        * @param $function_oid The OID 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} ";
+       function dropFunction($function_oid, $cascade) {
+               // Function comes in with $object as function OID
+               $fn = &$this->getFunction($function_oid);
+               $this->fieldClean($fn->f[$this->fnFields['fnname']]);
+               
+               $sql = "DROP FUNCTION \"{$fn->f[$this->fnFields['fnname']]}\"({$fn->f[$this->fnFields['fnarguments']]})";
                if ($cascade) $sql .= " CASCADE";
                
                return $this->execute($sql);
index e509731fb5718db9d1aa7238b4a675c0ed815a1b..2880a52394c20e2a0ba93f55957b8a8c63c082bd 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.45 2003/05/19 15:15:49 chriskl Exp $
+ * $Id: Postgres72.php,v 1.46 2003/06/01 11:53:47 chriskl Exp $
  */
 
 
@@ -211,6 +211,7 @@ class Postgres72 extends Postgres71 {
                
        /**
         * Updates (replaces) a function.
+        * @param $function_oid The OID of the function
         * @param $funcname The name of the function to create
         * @param $args The array of argument types
         * @param $returns The return type
@@ -220,7 +221,7 @@ class Postgres72 extends Postgres71 {
         * @param $setof True if returns a set, false otherwise
         * @return 0 success
         */
-       function setFunction($funcname, $args, $returns, $definition, $language, $flags, $setof) {
+       function setFunction($function_oid, $funcname, $args, $returns, $definition, $language, $flags, $setof) {
                return $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
        }
 
index e175ddedb6830aed39bd41b590c31e23a3071ec3..697072c2d243366a2f49d257bef10e94a6a5f5d4 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage functions in a database
         *
-        * $Id: functions.php,v 1.16 2003/05/31 07:23:24 chriskl Exp $
+        * $Id: functions.php,v 1.17 2003/06/01 11:53:45 chriskl Exp $
         */
 
        // Include application functions
@@ -19,7 +19,7 @@
        function doSaveEdit() {
                global $localData, $lang;
 
-               $status = $localData->setFunction($_POST['original_function'], $_POST['original_arguments'], 
+               $status = $localData->setFunction($_POST['function_oid'], $_POST['original_function'], $_POST['original_arguments'], 
                                                                                                                $_POST['original_returns'], $_POST['formDefinition'], 
                                                                                                                $_POST['original_lang'], $_POST['formProperties'], isset($_POST['original_setof']), true);
                if ($status == 0)
                        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=\"function_oid\" value=\"", htmlspecialchars($_REQUEST['function_oid']), "\">\n";
                        echo $misc->form;
                        // 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 "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\">\n";
+                       echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\">\n";
                        echo "</form>\n";
                }
                else {
-                       $status = $localData->dropFunction($_POST['function'], isset($_POST['cascade']));
+                       $status = $localData->dropFunction($_POST['function_oid'], isset($_POST['cascade']));
                        if ($status == 0)
                                doDefault($lang['strfunctiondropped']);
                        else
index 342f14fbc6a8c4ae7e3b74dc6660e58afeee7a4e..81cd31e0421e86e94d7e20fd049635e1a38b0777 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage privileges in a database
         *
-        * $Id: privileges.php,v 1.14 2003/05/23 03:10:59 chriskl Exp $
+        * $Id: privileges.php,v 1.15 2003/06/01 11:53:45 chriskl Exp $
         */
 
        // Include application functions
@@ -29,7 +29,9 @@
                // Set name
                switch ($_REQUEST['type']) {
                        case 'function':
-                               $name = $_REQUEST['function'];
+                               $fn = &$localData->getFunction($_REQUEST['object']);
+                               $data->fieldClean($fn->f[$data->fnFields['fnname']]);
+                               $name = $fn->f[$data->fnFields['fnname']] . "(". $fn->f[$data->fnFields['fnarguments']] .")";
                                break;
                        default:
                                $name = $_REQUEST['object'];
                        echo "</form>\n";
                }
                else {
-                       $status = $localData->setPrivileges(isset($_REQUEST['grant']) ? 'GRANT' : 'REVOKE', $_REQUEST['type'], $name,
+                       $status = $localData->setPrivileges(isset($_REQUEST['grant']) ? 'GRANT' : 'REVOKE', $_REQUEST['type'], $_REQUEST['object'],
                                isset($_REQUEST['public']), $_REQUEST['username'], $_REQUEST['groupname'], array_keys($_REQUEST['privilege']));
                        if ($status == 0)
                                doDefault($lang['strgranted']);