Permalink
Browse files

Add comment field to the create function form.

  • Loading branch information...
1 parent 06c2263 commit 1a1ec04d75cac2a7b39aa4c49b1986dbfce1e725 @ioguix ioguix committed Nov 17, 2008
Showing with 78 additions and 30 deletions.
  1. +30 −14 classes/database/Postgres.php
  2. +11 −12 classes/database/Postgres73.php
  3. +29 −2 classes/database/Postgres82.php
  4. +8 −2 functions.php
@@ -3967,19 +3967,10 @@ function setFunction($function_oid, $funcname, $newname, $args, $returns, $defin
}
// 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 @@ function setFunction($function_oid, $funcname, $newname, $args, $returns, $defin
return -5;
}
- $funcname = $newname;
+ $funcname = $newname;
}
// Alter the owner, if necessary
@@ -4036,10 +4027,21 @@ function setFunction($function_oid, $funcname, $newname, $args, $returns, $defin
* @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 @@ function createFunction($funcname, $args, $returns, $definition, $language, $fla
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();
}
/**
@@ -274,7 +274,6 @@ function getGroup($groname) {
* @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 @@ function setFunction($function_oid, $funcname, $newname, $args, $returns, $defin
// 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();
}
@@ -170,10 +170,23 @@ function getFunction($function_oid) {
* @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 @@ function createFunction($funcname, $args, $returns, $definition, $language, $fla
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
View
@@ -171,7 +171,7 @@ function doEdit($msg = '') {
// 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 @@ function doCreate($msg = '',$szJS="") {
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 @@ function doCreate($msg = '',$szJS="") {
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 @@ function doSaveCreate() {
$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 {

0 comments on commit 1a1ec04

Please sign in to comment.