From cd5a27f764689acab34e2115133e1a9644e6ca06 Mon Sep 17 00:00:00 2001 From: chriskl Date: Sun, 1 Jun 2003 11:53:45 +0000 Subject: [PATCH] fix all operations on functions with spaces, etc. --- BUGS | 1 - classes/database/Postgres.php | 33 +++++++++++++++++++-------------- classes/database/Postgres72.php | 5 +++-- functions.php | 10 ++++++---- privileges.php | 8 +++++--- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/BUGS b/BUGS index 5ad8133a..df1678fe 100644 --- 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 diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index a991c6d5..6a6b0490 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -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); diff --git a/classes/database/Postgres72.php b/classes/database/Postgres72.php index e509731f..2880a523 100644 --- a/classes/database/Postgres72.php +++ b/classes/database/Postgres72.php @@ -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); } diff --git a/functions.php b/functions.php index e175dded..697072c2 100644 --- a/functions.php +++ b/functions.php @@ -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) @@ -181,16 +181,18 @@ echo "
\n"; echo "\n"; echo "\n"; + echo "\n"; echo $misc->form; // Show cascade drop option if supportd if ($localData->hasDropBehavior()) { echo "

{$lang['strcascade']}

\n"; } - echo " \n"; + echo "\n"; + echo "\n"; echo "
\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 diff --git a/privileges.php b/privileges.php index 342f14fb..81cd31e0 100644 --- a/privileges.php +++ b/privileges.php @@ -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']; @@ -99,7 +101,7 @@ echo "\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']); -- 2.39.5