Add comment field to the create function form.
authorGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Mon, 17 Nov 2008 00:58:15 +0000 (19:58 -0500)
committerGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Mon, 17 Nov 2008 00:58:15 +0000 (19:58 -0500)
Reported by retrorocket : https://sourceforge.net/forum/message.php?msg_id=5247881

classes/database/Postgres.php
classes/database/Postgres73.php
classes/database/Postgres82.php
functions.php

index 6ab8caa7f4da9560b70c54df989c210c74508296..6c9b996c792147947363369e56d64c5446963290 100755 (executable)
@@ -3967,19 +3967,10 @@ class Postgres extends ADODB_base {
                }
 
                // Replace the existing function
-               $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, true);
+               $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment, true);
                if ($status != 0) {
                        $this->rollbackTransaction();
-                       return -3;
-               }
-
-               // Comment on the function
-               $this->fieldClean($funcname);
-               $this->clean($comment);
-               $status = $this->setComment('FUNCTION', "\"{$funcname}\"({$args})", null, $comment);
-               if ($status != 0) {
-                       $this->rollbackTransaction();
-                       return -4;
+                       return $status;
                }
 
                // Rename the function, if necessary
@@ -3992,7 +3983,7 @@ class Postgres extends ADODB_base {
                                return -5;
                        }
 
-                        $funcname = $newname;
+            $funcname = $newname;
                }
 
                // Alter the owner, if necessary
@@ -4036,10 +4027,21 @@ class Postgres extends ADODB_base {
         * @param $setof True if it returns a set, false otherwise
         * @param $rows number of rows planner should estimate will be returned
      * @param $cost cost the planner should use in the function execution step
+     * @param $comment Comment for the function
         * @param $replace (optional) True if OR REPLACE, false for normal
         * @return 0 success
+        * @return -3 create function failed
+        * @return -4 set comment failed
         */
-       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $replace = false) {
+       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment, $replace = false) {
+               
+               // Begin a transaction
+               $status = $this->beginTransaction();
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -1;
+               }
+               
                $this->fieldClean($funcname);
                $this->clean($args);
                $this->clean($language);
@@ -4087,7 +4089,21 @@ class Postgres extends ADODB_base {
                        else $sql .= "\n{$v}";
                }
 
-               return $this->execute($sql);
+               $status = $this->execute($sql);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -3;
+               }
+
+               /* set the comment */
+               $this->clean($comment);
+               $status = $this->setComment('FUNCTION', "\"{$funcname}\"({$args})", null, $comment);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -4;
+               }
+
+               return $this->endTransaction();
        }
 
        /**
index 6618de6456eb0a0dc8ec65462826dde25cdf3b98..87315b97f038be6ab78fd830e13a24331d93abd5 100644 (file)
@@ -274,7 +274,6 @@ class Postgres73 extends Postgres74 {
         * @return -1 transaction error
         * @return -2 drop function error
         * @return -3 create function error
-        * @return -4 comment error
         */
        function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $rows, $cost, $comment) {
                // Begin a transaction
@@ -287,32 +286,32 @@ class Postgres73 extends Postgres74 {
                // Replace the existing function
                if ($funcname != $newname) {
                        $status = $this->dropFunction($function_oid, false);
-               if ($status != 0) {
-                       $this->rollbackTransaction();
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
                                return -2;
-               }
+                       }
 
-                       $status = $this->createFunction($newname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, false);
-               if ($status != 0) {
-                       $this->rollbackTransaction();
+                       $status = $this->createFunction($newname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment, false);
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
                                return -3;
-       }
+                       }
                } else {
-                       $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, true);
+                       $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment, true);
                        if ($status != 0) {
                                $this->rollbackTransaction();
                                return -3;
+                       }
                }
-       }
 
                // Comment on the function
-               $this->fieldClean($newname);
+               /*$this->fieldClean($newname);
                $this->clean($comment);
                $status = $this->setComment('FUNCTION', "\"{$newname}\"({$args})", null, $comment);
                if ($status != 0) {
                        $this->rollbackTransaction();
                        return -4;
-               }
+               }*/
 
                return $this->endTransaction();
        }
index 89de03992876b8d8491df0ccd6f4f853673952e1..c30bfdd1aa7e4baabe7d998be29f0bca2c899f15 100644 (file)
@@ -170,10 +170,23 @@ class Postgres82 extends Postgres {
         * @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 $rows number of rows planner should estimate will be returned
+     * @param $cost cost the planner should use in the function execution step
+        * @param $comment The comment on the function
         * @param $replace (optional) True if OR REPLACE, false for normal
         * @return 0 success
+        * @return -1 create function failed
+        * @return -4 set comment failed
         */
-       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $replace = false) {
+       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment, $replace = false) {
+               
+               // Begin a transaction
+               $status = $this->beginTransaction();
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -1;
+               }
+               
                $this->fieldClean($funcname);
                $this->clean($args);
                $this->clean($language);
@@ -211,7 +224,21 @@ class Postgres82 extends Postgres {
                        else $sql .= "\n{$v}";
                }
 
-               return $this->execute($sql);
+               $status = $this->execute($sql);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -3;
+               }
+
+               /* set the comment */
+               $this->clean($comment);
+               $status = $this->setComment('FUNCTION', "\"{$funcname}\"({$args})", null, $comment);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -4;
+               }
+
+               return $this->endTransaction();
        }
 
        // Index functions
index bcdd0481dc4eb39a6fe22b2d373c3e3dd3ee0961..acbb4da2bc59ce06399cedfdff7bf5a55999fe02 100644 (file)
                        // Display function comment
                        echo "<tr><th class=\"data\" colspan=\"5\">{$lang['strcomment']}</th></tr>\n";
                        echo "<tr><td class=\"data1\" colspan=\"5\"><textarea style=\"width:100%;\" name=\"formComment\" rows=\"3\" cols=\"50\">",
-                                       htmlspecialchars($_POST['formComment']), "</textarea></td></tr>\n";
+                               htmlspecialchars($_POST['formComment']), "</textarea></td></tr>\n";
 
                        // Display function cost options
                        if ($data->hasFunctionCosting()) {
                if (!isset($_POST['formArray'])) $_POST['formArray'] = '';
                if (!isset($_POST['formCost'])) $_POST['formCost'] = '';
                if (!isset($_POST['formRows'])) $_POST['formRows'] = '';
+               if (!isset($_POST['formComment'])) $_POST['formComment'] = '';
 
                $types = $data->getTypes(true, true, true);
                $langs = $data->getLanguages(true);
                        echo "<tr><td class=\"data1\" colspan=\"4\"><textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\">",
                                htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";
                }
+               
+               // Display function comment
+               echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strcomment']}</th></tr>\n";
+               echo "<tr><td class=\"data1\" colspan=\"4\"><textarea style=\"width:100%;\" name=\"formComment\" rows=\"3\" cols=\"50\">",
+                       htmlspecialchars($_POST['formComment']), "</textarea></td></tr>\n";
 
                // Display function cost options
                if ($data->hasFunctionCosting()) {
                        $status = $data->createFunction($_POST['formFunction'], empty($_POST['nojs'])? buildFunctionArguments($_POST) : $_POST['formArguments'],
                                        $_POST['formReturns'] . $_POST['formArray'] , $def , $_POST['formLanguage'],
                                        $_POST['formProperties'], $_POST['formSetOf'] == 'SETOF',
-                                       $cost, $rows, false);
+                                       $cost, $rows, $_POST['formComment'], false);
                        if ($status == 0)
                                doDefault($lang['strfunctioncreated']);
                        else {