support creating srf's. show 'setof' in list of functions. xhtml fixes move some...
authorchriskl <chriskl>
Sun, 11 May 2003 15:13:29 +0000 (15:13 +0000)
committerchriskl <chriskl>
Sun, 11 May 2003 15:13:29 +0000 (15:13 +0000)
classes/database/BaseDB.php
classes/database/Postgres.php
classes/database/Postgres72.php
classes/database/Postgres73.php
functions.php

index 062f6a2602b59babbdda921bb8a5d060fc320040..83e84eef8162d4d64dbea2fa044a3158f3f0417f 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: BaseDB.php,v 1.15 2003/05/10 13:15:42 chriskl Exp $
+ * $Id: BaseDB.php,v 1.16 2003/05/11 15:13:29 chriskl Exp $
  */
 
 include_once('classes/database/ADODB_base.php');
@@ -190,6 +190,7 @@ class BaseDB extends ADODB_base {
        function hasGrantOption() { return false; }
        function hasCluster() { return false; }
        function hasDropBehavior() { return false; }
+       function hasSRFs() { return false; }
 
 }
 
index 86f33025c49ebcff33d7d8708d6f0d6d59402bb6..cdb322a9499ad6c14124f3025dc5e5d427d8ccc8 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.100 2003/05/11 10:39:29 chriskl Exp $
+ * $Id: Postgres.php,v 1.101 2003/05/11 15:13:30 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -27,6 +27,7 @@ class Postgres extends BaseDB {
                'typout' => 'typout', 'typlen' => 'typlen', 'typdef' => 'typdef', 'typelem' => 'typelem',
                'typdelim' => 'typdelim', 'typbyval' => 'typbyval', 
                'typalign' => 'typalign', 'typstorage' => 'typstorage');
+       var $fnFields = array('fnname' => 'proname', 'fnreturns' => 'return_type', 'fnarguments' => 'arguments','fnoid' => 'oid', 'fndef' => 'source', 'fnlang' => 'language', 'setof' => 'proretset' );
 
        // Array of allowed type alignments
        var $typAligns = array('char', 'int2', 'int4', 'double');
@@ -2154,24 +2155,29 @@ 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 $funcname The name of the function to update
-        * @param $definition The new definition for the function
+        * @param $funcname The name of the function to create
+        * @param $args The array of argument types
+        * @param $returns The return type
+        * @param $definition The definition for the new function
+        * @param $language The language the function is written for
+        * @param $flags An array of optional flags
+        * @param $setof True if returns a set, false otherwise
         * @return 0 success
         * @return -1 transaction error
         * @return -2 drop function error
         * @return -3 create function error
         */
-       function setFunction($funcname, $definition) {
+       function setFunction($funcname, $args, $returns, $definition, $language, $flags, $setof) {
                $status = $this->beginTransaction();
                if ($status != 0) return -1;
 
-               $status = $this->dropFunction($funcname);
+               $status = $this->dropFunction($funcname, false);
                if ($status != 0) {
                        $this->rollbackTransaction();
                        return -2;
                }
                
-               $status = $this->createFunction($funcname, $definition);
+               $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, false);
                if ($status != 0) {
                        $this->rollbackTransaction();
                        return -3;
@@ -2189,10 +2195,12 @@ class Postgres extends BaseDB {
         * @param $definition The definition for the new function
         * @param $language The language the function is written for
         * @param $flags An array of optional flags
+        * @param $setof True if it returns a set, false otherwise
         * @param $replace (optional) True if OR REPLACE, false for normal
         * @return 0 success
         */
-       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $replace = false) {
+       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $replace = false) {
+               if ($setof) return -99;
                $this->fieldClean($funcname);
                $this->clean($args);
                $this->fieldClean($returns);
index f54f6d166ec505b276005128e3cabb23e17f598a..f9bf827f915d2f8c779df01d48e48dedb0235c04 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.41 2003/05/07 15:00:56 chriskl Exp $
+ * $Id: Postgres72.php,v 1.42 2003/05/11 15:13:30 chriskl Exp $
  */
 
 
@@ -12,7 +12,6 @@ include_once('classes/database/Postgres71.php');
 
 class Postgres72 extends Postgres71 {
 
-       var $fnFields = array('fnname' => 'proname', 'fnreturns' => 'return_type', 'fnarguments' => 'arguments','fnoid' => 'oid', 'fndef' => 'source', 'fnlang' => 'language' );
        var $langFields = array('lanname' => 'lanname');
        var $privFields = array('privarr' => 'relacl');
 
@@ -228,6 +227,7 @@ class Postgres72 extends Postgres71 {
                $sql = "SELECT
                                p.oid,
                                p.proname,
+                               false AS proretset,
                                format_type(p.prorettype, NULL) AS return_type,
                                oidvectortypes(p.proargtypes) AS arguments
                        FROM
@@ -277,10 +277,11 @@ class Postgres72 extends Postgres71 {
         * @param $definition The definition for the new function
         * @param $language The language the function is written for
         * @param $flags An array of optional flags
+        * @param $setof True if returns a set, false otherwise
         * @return 0 success
         */
-       function setFunction($funcname, $args, $returns, $definition, $language, $flags) {
-               return $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, true);
+       function setFunction($funcname, $args, $returns, $definition, $language, $flags, $setof) {
+               return $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
        }
 
        // Type functions
index 49db37b22e47310508eb030bf59deda161b6cc7b..4618168e0db8ba469f97e50c437775ef4bb27188 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres73.php,v 1.42 2003/05/11 10:39:29 chriskl Exp $
+ * $Id: Postgres73.php,v 1.43 2003/05/11 15:13:31 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -515,8 +515,8 @@ class Postgres73 extends Postgres72 {
                                {$distinct}
                                p.oid,
                                p.proname,
-                               CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||
-                                       pg_catalog.format_type(p.prorettype, NULL) AS return_type,
+                               p.proretset,
+                               pg_catalog.format_type(p.prorettype, NULL) AS return_type,
                                pg_catalog.oidvectortypes(p.proargtypes) AS arguments
                        FROM pg_catalog.pg_proc p
                        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
@@ -545,10 +545,11 @@ class Postgres73 extends Postgres72 {
         * @param $definition The definition for the new function
         * @param $language The language the function is written for
         * @param $flags An array of optional flags
+        * @param $setof True if it returns a set, false otherwise
         * @param $replace (optional) True if OR REPLACE, false for normal
         * @return 0 success
         */
-       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $replace = false) {
+       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $replace = false) {
                $this->fieldClean($funcname);
                $this->clean($args);
                $this->fieldClean($returns);
@@ -564,7 +565,9 @@ class Postgres73 extends Postgres72 {
                        $sql .= $args;
 
                // For some reason, the returns field cannot have quotes...
-               $sql .= ") RETURNS {$returns} AS '\n";
+               $sql .= ") RETURNS ";
+               if ($setof) $sql .= "SETOF ";
+               $sql .= "{$returns} AS '\n";
                $sql .= $definition;
                $sql .= "\n'";
                $sql .= " LANGUAGE \"{$language}\"";
@@ -775,6 +778,7 @@ class Postgres73 extends Postgres72 {
        function hasCluster() { return true; }
        function hasDropBehavior() { return true; }
        function hasDropColumn() { return true; }
+       function hasSRFs() { return true; }
 
 }
 
index 9b809209d967294aed3416881c11503b365ecf64..a4ceec62be10f60b51bcdc2fcc65ee7663409a35 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage functions in a database
         *
-        * $Id: functions.php,v 1.11 2003/05/11 10:39:29 chriskl Exp $
+        * $Id: functions.php,v 1.12 2003/05/11 15:13:29 chriskl Exp $
         */
 
        // Include application functions
                
                if ($funcdata->recordCount() > 0) {
                        $func_full = $funcdata->f[$data->fnFields['fnname']] . "(". $funcdata->f[$data->fnFields['fnarguments']] .")";
-                       echo "<table width=90%>\n";
-                       echo "<tr><th class=data>{$lang['strfunctions']}</th>\n";
-                       echo "<th class=data>{$lang['strarguments']}</th>\n";
-                       echo "<th class=data>{$lang['strreturns']}</th>\n";
-                       echo "<th class=data>{$lang['strlanguage']}</th></tr>\n";
-                       echo "<tr><td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnname']]), "</td>\n";
-                       echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnarguments']]), "</td>\n";
-                       echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnreturns']]), "</td>\n";
-                       echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnlang']]), "</td></tr>\n";
-                       echo "<tr><th class=data colspan=4>{$lang['strdefinition']}</th></tr>\n";
-                       echo "<tr><td class=data1 colspan=4>", nl2br(htmlspecialchars($funcdata->f[$data->fnFields['fndef']])), "</td></tr>\n";
+                       echo "<table width=\"90%\">\n";
+                       echo "<tr><th class=\"data\">{$lang['strfunctions']}</th>\n";
+                       echo "<th class=\"data\">{$lang['strarguments']}</th>\n";
+                       echo "<th class=\"data\">{$lang['strreturns']}</th>\n";
+                       echo "<th class=\"data\">{$lang['strlanguage']}</th></tr>\n";
+                       echo "<tr><td class=\"data1\">", htmlspecialchars($funcdata->f[$data->fnFields['fnname']]), "</td>\n";
+                       echo "<td class=\"data1\">", htmlspecialchars($funcdata->f[$data->fnFields['fnarguments']]), "</td>\n";
+                       echo "<td class=\"data1\">", htmlspecialchars($funcdata->f[$data->fnFields['fnreturns']]), "</td>\n";
+                       echo "<td class=\"data1\">", htmlspecialchars($funcdata->f[$data->fnFields['fnlang']]), "</td></tr>\n";
+                       echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strdefinition']}</th></tr>\n";
+                       echo "<tr><td class=\"data1\" colspan=\"4\">", nl2br(htmlspecialchars($funcdata->f[$data->fnFields['fndef']])), "</td></tr>\n";
                        echo "</table>\n";
                }
                else echo "<p>{$lang['strnodata']}</p>\n";
                if (!isset($_POST['formLanguage'])) $_POST['formLanguage'] = '';
                if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = '';
                if (!isset($_POST['formProperties'])) $_POST['formProperties'] = $data->defaultprops;
+               if (!isset($_POST['formSetOf'])) $_POST['formSetOf'] = '';
                
                $types = &$localData->getTypes(true);
                $langs = &$localData->getLanguages();
                echo "<td class=\"data1\"><input name=\"formArguments\" style=\"width:100%;\" size=\"16\" value=\"",
                        htmlspecialchars($_POST['formArguments']), "\" /></td>\n";
 
-               echo "<td class=\"data1\"><select name=\"formReturns\">\n";
+               echo "<td class=\"data1\">\n";
+               // If supports set-returning-functions, output setof option
+               if ($data->hasSRFs()) {
+                       echo "<select name=\"formSetOf\">\n";
+                       echo "<option value=\"\"", ($_POST['formSetOf'] == '') ? ' selected' : '', "></option>\n";
+                       echo "<option value=\"SETOF\"", ($_POST['formSetOf'] == 'SETOF') ? ' selected' : '', ">SETOF</option>\n";
+                       echo "</select>\n";
+               }
+               // Output return type list              
+               echo "<select name=\"formReturns\">\n";
                while (!$types->EOF) {
                        echo "<option value=\"", htmlspecialchars($types->f[$data->typFields['typname']]), "\"", 
                                ($types->f[$data->typFields['typname']] == $_POST['formReturns']) ? ' selected' : '', ">",
                else {           
                        $status = $localData->createFunction($_POST['formFunction'], $_POST['formArguments'] , 
                                        $_POST['formReturns'] , $_POST['formDefinition'] , $_POST['formLanguage'], 
-                                       $_POST['formProperties'], false);
+                                       $_POST['formProperties'], $_POST['formSetOf'] == 'SETOF', false);
                        if ($status == 0)
                                doDefault($lang['strfunctioncreated']);
                        else
 
                if ($funcs->recordCount() > 0) {
                        echo "<table>\n";
-                       echo "<tr><th class=data>{$lang['strfunctions']}</th><th class=data>{$lang['strreturns']}</th><th class=data>{$lang['strarguments']}</th><th colspan=\"4\" class=data>{$lang['stractions']}</th>\n";
+                       echo "<tr><th class=\"data\">{$lang['strfunctions']}</th><th class=\"data\">{$lang['strreturns']}</th>\n";
+                       echo "<th class=\"data\">{$lang['strarguments']}</th><th colspan=\"4\" class=\"data\">{$lang['stractions']}</th>\n";
                        $i = 0;
                        while (!$funcs->EOF) {
+                               $funcs->f[$data->fnFields['setof']] = $data->phpBool($funcs->f[$data->fnFields['setof']]);
                                $func_full = $funcs->f[$data->fnFields['fnname']] . "(". $funcs->f[$data->fnFields['fnarguments']] .")";
                                $id = (($i % 2) == 0 ? '1' : '2');
-                               echo "<tr><td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnname']]), "</td>\n";
-                               echo "<td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnreturns']]), "</td>\n";
-                               echo "<td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnarguments']]), "</td>\n";
-                               echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=properties&{$misc->href}&function=", 
+                               echo "<tr><td class=\"data{$id}\">", htmlspecialchars($funcs->f[$data->fnFields['fnname']]), "</td>\n";
+                               echo "<td class=\"data{$id}\">";
+                               if ($funcs->f[$data->fnFields['setof']]) echo "setof ";
+                               echo htmlspecialchars($funcs->f[$data->fnFields['fnreturns']]), "</td>\n";
+                               echo "<td class=\"data{$id}\">", htmlspecialchars($funcs->f[$data->fnFields['fnarguments']]), "</td>\n";
+                               echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=properties&{$misc->href}&function=", 
                                        urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">{$lang['strproperties']}</a></td>\n";
-                               echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=edit&{$misc->href}&function=", 
+                               echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=edit&{$misc->href}&function=", 
                                        urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">{$lang['stredit']}</a></td>\n";
-                               echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&function=",
+                               echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&function=",
                                        urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">{$lang['strdrop']}</a></td>\n";
-                               echo "<td class=opbutton{$id}><a href=\"privileges.php?{$misc->href}&function=", 
+                               echo "<td class=\"opbutton{$id}\"><a href=\"privileges.php?{$misc->href}&function=", 
                                        urlencode($func_full), "&object=",
                                        $funcs->f[$data->fnFields['fnoid']], "&type=function\">{$lang['strprivileges']}</a></td>\n";
                                echo "</tr>\n";
                        echo "<p>{$lang['strnofunctions']}</p>\n";
                }
                
-               echo "<p><a class=navlink href=\"$PHP_SELF?action=create&{$misc->href}\">{$lang['strcreatefunction']}</a></p>\n";
+               echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}\">{$lang['strcreatefunction']}</a></p>\n";
 
        }