From a8d1428e599cb4168ccf50a09e0df0568fa43314 Mon Sep 17 00:00:00 2001 From: xzilla Date: Tue, 17 Sep 2002 21:38:51 +0000 Subject: [PATCH] Did some work on being able to create functions. You can actually create new functions, but it's broken becuase I'm not handeling the escaped ticks correctly. (think return \'\'t\'\'; ) --- classes/database/Postgres72.php | 45 +++++++++++++++-- lang/english.php | 4 +- public_html/functions.php | 85 ++++++++++++++++++++++++--------- 3 files changed, 108 insertions(+), 26 deletions(-) diff --git a/classes/database/Postgres72.php b/classes/database/Postgres72.php index 58348c3d..2884489d 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.8 2002/09/17 12:40:01 chriskl Exp $ + * $Id: Postgres72.php,v 1.9 2002/09/17 21:38:51 xzilla Exp $ */ @@ -14,6 +14,7 @@ class Postgres72 extends Postgres71 { var $fnFields = array('fnname' => 'proname', 'fnreturns' => 'return_type', 'fnarguments' => 'arguments','fnoid' => 'oid', 'fndef' => 'source', 'fnlang' => 'language' ); var $typFields = array('typname' => 'typname'); + var $langFields = array('lanname' => 'lanname'); // @@ Set the maximum built-in ID. Should we bother querying for this? var $_lastSystemOID = 16554; @@ -111,22 +112,47 @@ class Postgres72 extends Postgres71 { * @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); - $this->arrayClean($args); +// if (is_array($args)) { +// $this->arrayClean($args); +// } + $this->clean($args); $this->clean($returns); $this->clean($definition); $this->clean($language); - $this->arrayClean($flags); +// if (is_array($flags)) { +// $this->arrayClean($flags); +// } + $this->clean($replace); $sql = "CREATE"; if ($replace) $sql .= " OR REPLACE"; $sql .= " FUNCTION \"{$funcname}\" ("; +/* if (sizeof($args) > 0) $sql .= '"' . join('", "', $args) . '"'; +*/ + if ($args) + $sql .= $args; + $sql .= ") RETURNS \"{$returns}\" AS '\n{$definition}\n'"; $sql .= " LANGUAGE \"{$language}\""; +/* if (sizeof($flags) > 0) $sql .= ' WITH ("' . join('", "', $flags) . '")'; +*/ + return $this->execute($sql); } @@ -186,6 +212,19 @@ class Postgres72 extends Postgres71 { return $this->selectSet($sql); } + // Function Languages + + /** + * Returns a list of all languages in the database + * @return A recordset + */ + function &getLangs() { + $sql = "SELECT lanname FROM pg_language ORDER BY lanname DESC"; + + return $this->selectSet($sql); + } + + } ?> diff --git a/lang/english.php b/lang/english.php index 0e1db0f7..5f2a4344 100755 --- a/lang/english.php +++ b/lang/english.php @@ -4,7 +4,7 @@ * Language template file for WebDB. Use this to base language * files. * - * $Id: english.php,v 1.4 2002/09/16 10:12:01 chriskl Exp $ + * $Id: english.php,v 1.5 2002/09/17 21:38:51 xzilla Exp $ */ $appLang = 'english'; @@ -61,4 +61,6 @@ $strReturns = 'Returns'; $strArguments = 'Arguments'; $strLanguage = 'Language'; + $strFunctionNeedsName = 'You must give a name for your function.'; + $strFunctionNeedsDef = 'You must give a definition for your function.'; ?> diff --git a/public_html/functions.php b/public_html/functions.php index 9e28c7bc..c203ddf3 100644 --- a/public_html/functions.php +++ b/public_html/functions.php @@ -3,7 +3,7 @@ /** * Manage functions in a database * - * $Id: functions.php,v 1.4 2002/09/16 15:09:54 chriskl Exp $ + * $Id: functions.php,v 1.5 2002/09/17 21:38:51 xzilla Exp $ */ // Include application functions @@ -31,21 +31,47 @@ */ function doEdit($msg = '') { global $data, $localData, $misc; - global $PHP_SELF, $strName, $strDefinition; + global $PHP_SELF, $strFunction, $strArguments, $strReturns, $strActions, $strNoFunctions, $strDefinition, $strLanguage; echo "

", htmlspecialchars($_REQUEST['database']), ": Functions: ", htmlspecialchars($_REQUEST['function']), ": Edit

\n"; $misc->printMsg($msg); - $fndata = &$localData->getFunction($_REQUEST['function']); + $fndata = &$localData->getFunction($_REQUEST['function_oid']); if ($fndata->recordCount() > 0) { echo "
\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; + echo "
{$strName}
", htmlspecialchars($fndata->f[$data->vwFields['vwname']]), "
{$strDefinition}
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + + echo "\n"; + echo "\n"; + + echo "\n"; + + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; echo "
{$strFunction}{$strArguments}{$strReturns}{$strLanguage}
\n"; + echo "\n"; + echo "", htmlspecialchars($fndata->f[$data->fnFields['fnreturns']]), "", htmlspecialchars($fndata->f[$data->fnFields['fnlang']]), "
{$strDefinition}
\n"; echo "\n"; echo "\n"; @@ -137,36 +163,50 @@ */ function doCreate($msg = '') { global $data, $localData, $misc; - global $PHP_SELF, $strName, $strArguments, $strReturns, $strDefinition; + global $PHP_SELF, $strName, $strArguments, $strReturns, $strDefinition, $strLanguage; if (!isset($_POST['formFunction'])) $_POST['formFunction'] = ''; if (!isset($_POST['formArguments'])) $_POST['formArguments'] = ''; if (!isset($_POST['formReturns'])) $_POST['formReturns'] = ''; + if (!isset($_POST['formLanguage'])) $_POST['formLanguage'] = ''; if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = ''; $types = &$localData->getTypes(); + $langs = &$localData->getLangs(); echo "

", htmlspecialchars($_REQUEST['database']), ": Functions: Create Function

\n"; $misc->printMsg($msg); echo "\n"; - echo "\n"; - echo "\n"; + echo "
{$strName}
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; + + echo "\n"; + + echo "\n"; - echo "\n"; - echo "\n"; echo "
{$strName}{$strArguments}{$strReturns}{$strLanguage}
_maxNameLen} maxlength={$data->_maxNameLen} value=\"", - htmlspecialchars($_POST['formFunction']), "\">
{$strArguments}
_maxNameLen} maxlength={$data->_maxNameLen} value=\"", - htmlspecialchars($_POST['formArguments']), "\">
{$strReturns}
_maxNameLen} maxlength={$data->_maxNameLen} value=\"", + htmlspecialchars($_POST['formArguments']), "\">
{$strDefinition}
\n"; echo "\n"; @@ -187,7 +227,7 @@ if ($_POST['formFunction'] == '') doCreate($strFunctionNeedsName); elseif ($_POST['formDefinition'] == '') doCreate($strFunctionNeedsDef); else { - $status = $localData->createFunction($_POST['formFunction'], $_POST['formDefinition']); + $status = $localData->createFunction($_POST['formFunction'], $_POST['formArguments'] , $_POST['formReturns'] , $_POST['formDefinition'] , $_POST['formLanguage'],0,"true"); if ($status == 0) doDefault('Function created.'); else @@ -219,7 +259,8 @@ echo "", htmlspecialchars($funcs->f[$data->fnFields['fnarguments']]), "\n"; echo "Properties\n"; - echo "Edit\n"; + echo "Edit\n"; echo "Drop\n"; echo "\n"; -- 2.39.5