Did some work on being able to create functions. You can actually create new function...
authorxzilla <xzilla>
Tue, 17 Sep 2002 21:38:51 +0000 (21:38 +0000)
committerxzilla <xzilla>
Tue, 17 Sep 2002 21:38:51 +0000 (21:38 +0000)
(think return \'\'t\'\'; )

classes/database/Postgres72.php
lang/english.php
public_html/functions.php

index 58348c3d04c899d9c959ced5ee81147db0bb9f3f..2884489d2ebcf3f26dc5321d50ed09c2d11dc388 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.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);
+       }
+
+
 }
 
 ?>
index 0e1db0f7978b92da2eb4e5c44e9b6f5a4012ed73..5f2a43444f1f248a72fe3243bb0fea1996be5590 100755 (executable)
@@ -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.';
 ?>
index 9e28c7bc70aaffc561a64232bd73b98ac9b66a13..c203ddf3f1c4fbd41d52702e799f7afb5650702e 100644 (file)
@@ -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
         */
        function doEdit($msg = '') {
                global $data, $localData, $misc;
-               global $PHP_SELF, $strName, $strDefinition;
+               global $PHP_SELF, $strFunction, $strArguments, $strReturns, $strActions, $strNoFunctions, $strDefinition, $strLanguage;
                
                echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions: ", htmlspecialchars($_REQUEST['function']), ": Edit</h2>\n";
                $misc->printMsg($msg);
 
-               $fndata = &$localData->getFunction($_REQUEST['function']);
+               $fndata = &$localData->getFunction($_REQUEST['function_oid']);
                
                if ($fndata->recordCount() > 0) {
                        echo "<form action=\"$PHP_SELF\" method=post>\n";
-                       echo "<table width=100%>\n";
-                       echo "<tr><th class=data>{$strName}</th></tr>\n";
-                       echo "<tr><td class=data1>", htmlspecialchars($fndata->f[$data->vwFields['vwname']]), "</td></tr>\n";
-                       echo "<tr><th class=data>{$strDefinition}</th></tr>\n";
-                       echo "<tr><td class=data1><textarea style=\"width:100%;\" rows=20 cols=50 name=formDefinition wrap=virtual>", 
-                               htmlspecialchars($fndata->f[$data->vwFields['vwdef']]), "</textarea></td></tr>\n";
+                       echo "<table width=90%>\n";
+                       echo "<tr>\n";
+                       echo "<th class=data>{$strFunction}</th>\n";
+                       echo "<th class=data>{$strArguments}</th>\n";
+                       echo "<th class=data>{$strReturns}</th>\n";
+                       echo "<th class=data>{$strLanguage}</th>\n";
+                       echo "</tr>\n";
+                               
+
+                       echo "<tr>\n";
+                       echo "<td class=data1><input type=text name=function value=", 
+                                       htmlspecialchars($fndata->f[$data->fnFields['fnname']]), 
+                                       ">\n";
+                       echo "<input type=hidden name=original_function value=", 
+                                       htmlspecialchars($fndata->f[$data->fnFields['fnname']]), 
+                                       "></td>\n";
+
+                       echo "<td class=data1><input type=text name=arguments value=", 
+                                       htmlspecialchars($fndata->f[$data->fnFields['fnarguments']]),
+                                       ">\n";
+                       echo "<input type=hidden name=original_arguments value=", 
+                                       htmlspecialchars($fndata->f[$data->fnFields['fnarguments']]), 
+                                       "></td>\n";
+
+
+                       echo "<td class=data1>", htmlspecialchars($fndata->f[$data->fnFields['fnreturns']]), "</td>\n";
+                       echo "<td class=data1>", htmlspecialchars($fndata->f[$data->fnFields['fnlang']]), "</td>\n";
+                       echo "</tr>\n";
+
+                       echo "<tr><th class=data colspan=8>{$strDefinition}</th></tr>\n";
+                       echo "<tr><td class=data1 colspan=8><textarea style=\"width:100%;\" rows=20 cols=50 name=formDefinition wrap=virtual>", 
+                               htmlspecialchars($fndata->f[$data->fnFields['fndef']]), "</textarea></td></tr>\n";
                        echo "</table>\n";
                        echo "<input type=hidden name=action value=save_edit>\n";
                        echo "<input type=hidden name=function value=\"", htmlspecialchars($_REQUEST['function']), "\">\n";
         */
        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 "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions: Create Function</h2>\n";
                $misc->printMsg($msg);
                
                echo "<form action=\"$PHP_SELF\" method=post>\n";
-               echo "<table width=100%>\n";
-               echo "<tr><th class=data>{$strName}</th></tr>\n";
+               echo "<table width=90%>\n";
+               echo "<tr><th class=data>{$strName}</th>\n";
+               echo "<th class=data>{$strArguments}</th>\n";
+               echo "<th class=data>{$strReturns}</th>\n";
+               echo "<th class=data>{$strLanguage}</th></tr>\n";
+
                echo "<tr><td class=data1><input name=formFunction size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"",
-                       htmlspecialchars($_POST['formFunction']), "\"></td></tr>\n";
-               echo "<tr><th class=data>{$strArguments}</th></tr>\n";
-               echo "<tr><td class=data1><input name=formArguments style=\"width:100%;\" size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"",
-                       htmlspecialchars($_POST['formArguments']), "\"></td></tr>\n";
-               echo "<tr><th class=data>{$strReturns}</th></tr>\n";
-               echo "<tr><td class=data1><select name=formReturns>\n";
+                       htmlspecialchars($_POST['formFunction']), "\"></td>\n";
+
+               echo "<td class=data1><input name=formArguments style=\"width:100%;\" size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"",
+                       htmlspecialchars($_POST['formArguments']), "\"></td>\n";
+
+               echo "<td class=data1><select name=formReturns>\n";
                while (!$types->EOF) {
                        echo "<option value=\"", htmlspecialchars($types->f[$data->typFields['typname']]), "\">",
                                htmlspecialchars($types->f[$data->typFields['typname']]), "</option>\n";
                        $types->moveNext();
                }
+
+               echo "<td class=data1><select name=formLanguage>\n";
+               while (!$langs->EOF) {
+                       echo "<option value=\"", htmlspecialchars($langs->f[$data->langFields['lanname']]), "\">",
+                               htmlspecialchars($langs->f[$data->langFields['lanname']]), "</option>\n";
+                       $langs->moveNext();
+               }
+
                echo "</td></tr>\n";
-               echo "<tr><th class=data>{$strDefinition}</th></tr>\n";
-               echo "<tr><td class=data1><textarea style=\"width:100%;\" rows=20 cols=50 name=formDefinition wrap=virtual>",
+               echo "<tr><th class=data colspan=4>{$strDefinition}</th></tr>\n";
+               echo "<tr><td class=data1 colspan=4><textarea style=\"width:100%;\" rows=20 cols=50 name=formDefinition wrap=virtual>",
                        htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";
                echo "</table>\n";
                echo "<input type=hidden name=action value=save_create>\n";
                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
                                echo "<td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnarguments']]), "</td>\n";
                                echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=properties&database=",
                                        htmlspecialchars($_REQUEST['database']), "&function=", urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">Properties</a></td>\n";
-                               echo "<td class=opbutton{$id}>Edit</td>\n";
+                               echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=edit&database=",
+                                       htmlspecialchars($_REQUEST['database']), "&function=", urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">Edit</a></td>\n";
                                echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_drop&database=", 
                                        htmlspecialchars($_REQUEST['database']), "&function=", urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">Drop</a></td>\n";
                                echo "</tr>\n";