diff options
author | Guillaume (ioguix) de Rorthais | 2008-11-17 00:58:15 +0000 |
---|---|---|
committer | Guillaume (ioguix) de Rorthais | 2008-11-17 00:58:15 +0000 |
commit | 1a1ec04d75cac2a7b39aa4c49b1986dbfce1e725 (patch) | |
tree | 41b45cd1a154a46907f0b16226bf5c475cf1b28c | |
parent | 06c2263c185db44c5722fc32062e8849b4058c0c (diff) |
Add comment field to the create function form.
Reported by retrorocket : https://sourceforge.net/forum/message.php?msg_id=5247881
-rwxr-xr-x | classes/database/Postgres.php | 44 | ||||
-rw-r--r-- | classes/database/Postgres73.php | 23 | ||||
-rw-r--r-- | classes/database/Postgres82.php | 31 | ||||
-rw-r--r-- | functions.php | 10 |
4 files changed, 78 insertions, 30 deletions
diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index 6ab8caa7..6c9b996c 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -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(); } /** diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index 6618de64..87315b97 100644 --- a/classes/database/Postgres73.php +++ b/classes/database/Postgres73.php @@ -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(); } diff --git a/classes/database/Postgres82.php b/classes/database/Postgres82.php index 89de0399..c30bfdd1 100644 --- a/classes/database/Postgres82.php +++ b/classes/database/Postgres82.php @@ -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 diff --git a/functions.php b/functions.php index bcdd0481..acbb4da2 100644 --- a/functions.php +++ b/functions.php @@ -171,7 +171,7 @@ // 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()) { @@ -434,6 +434,7 @@ 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); @@ -597,6 +598,11 @@ 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()) { @@ -678,7 +684,7 @@ $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 { |