* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.81 2003/04/30 06:35:41 chriskl Exp $
+ * $Id: Postgres.php,v 1.82 2003/04/30 06:49:11 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
return $this->selectSet($sql);
}
- // Type conversion routines
+ // Function functions
+
+ /**
+ * Returns a list of all functions that can be used in triggers
+ */
+ function &getTriggerFunctions() {
+ return $this->getFunctions(true);
+ }
+
+ /**
+ * 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
+ * @return 0 success
+ * @return -1 transaction error
+ * @return -2 drop function error
+ * @return -3 create function error
+ */
+ function setFunction($funcname, $definition) {
+ $status = $this->beginTransaction();
+ if ($status != 0) return -1;
+
+ $status = $this->dropFunction($funcname);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -2;
+ }
+
+ $status = $this->createFunction($funcname, $definition);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -3;
+ }
+
+ $status = $this->endTransaction();
+ return ($status == 0) ? 0 : -1;
+ }
+
+ /**
+ * Creates a new 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 $replace (optional) True if OR REPLACE, false for normal
+ * @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);
+// if (is_array($args)) {
+// $this->arrayClean($args);
+// }
+ $this->clean($args);
+ $this->clean($returns);
+ $this->clean($definition);
+ $this->clean($language);
+// if (is_array($flags)) {
+// $this->arrayClean($flags);
+// }
+
+ $sql = "CREATE";
+ if ($replace) $sql .= " OR REPLACE";
+ $sql .= " FUNCTION \"{$funcname}\" (";
+/*
+ if (sizeof($args) > 0)
+ $sql .= '"' . join('", "', $args) . '"';
+*/
+ if ($args)
+ $sql .= $args;
+
+ // For some reason, the returns field cannot have quotes...
+ $sql .= ") RETURNS {$returns} AS '\n";
+ $sql .= $definition;
+ $sql .= "\n'";
+ $sql .= " LANGUAGE \"{$language}\"";
+/*
+ if (sizeof($flags) > 0)
+ $sql .= ' WITH ("' . join('", "', $flags) . '")';
+*/
+
+
+ return $this->execute($sql);
+ }
+
+ /**
+ * Drops a function.
+ * @param $funcname The name of the function to drop
+ * @param $cascade True to cascade drop, false to restrict
+ * @return 0 success
+ */
+ function dropFunction($funcname, $cascade) {
+ $this->clean($funcname);
+
+ $sql = "DROP FUNCTION {$funcname} ";
+ if ($cascade) $sql .= " CASCADE";
+
+ return $this->execute($sql);
+ }
+
+ // Type conversion routines
/**
* Change the value of a parameter to 't' or 'f' depending on whether it evaluates to true or false
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres71.php,v 1.29 2003/03/27 12:56:30 chriskl Exp $
+ * $Id: Postgres71.php,v 1.30 2003/04/30 06:49:12 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
return $this->selectSet($sql);
}
- /**
- * Returns a list of all functions that can be used in triggers
- */
- function &getTriggerFunctions() {
- return $this->getFunctions(true);
- }
-
- /**
- * 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
- * @return 0 success
- * @return -1 transaction error
- * @return -2 drop function error
- * @return -3 create function error
- */
- function setFunction($funcname, $definition) {
- $status = $this->beginTransaction();
- if ($status != 0) return -1;
-
- $status = $this->dropFunction($funcname);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -2;
- }
-
- $status = $this->createFunction($funcname, $definition);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -3;
- }
-
- $status = $this->endTransaction();
- return ($status == 0) ? 0 : -1;
- }
-
/**
* Return all information relating to a table
* @param $table The name of the table
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres72.php,v 1.35 2003/04/28 12:07:28 chriskl Exp $
+ * $Id: Postgres72.php,v 1.36 2003/04/30 06:49:12 chriskl Exp $
*/
";
return $this->selectSet($sql);
- }
-
- /**
- * Creates a new 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 $replace (optional) True if OR REPLACE, false for normal
- * @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);
-// if (is_array($args)) {
-// $this->arrayClean($args);
-// }
- $this->clean($args);
- $this->clean($returns);
- $this->clean($definition);
- $this->clean($language);
-// if (is_array($flags)) {
-// $this->arrayClean($flags);
-// }
-
- $sql = "CREATE";
- if ($replace) $sql .= " OR REPLACE";
- $sql .= " FUNCTION \"{$funcname}\" (";
-/*
- if (sizeof($args) > 0)
- $sql .= '"' . join('", "', $args) . '"';
-*/
- if ($args)
- $sql .= $args;
-
- // For some reason, the returns field cannot have quotes...
- $sql .= ") RETURNS {$returns} AS '\n";
- $sql .= $definition;
- $sql .= "\n'";
- $sql .= " LANGUAGE \"{$language}\"";
-/*
- if (sizeof($flags) > 0)
- $sql .= ' WITH ("' . join('", "', $flags) . '")';
-*/
-
-
- return $this->execute($sql);
- }
-
- /**
- * Drops a function.
- * @param $funcname The name of the function to drop
- * @return 0 success
- */
- function dropFunction($funcname) {
- $this->clean($funcname);
-
- $sql = "DROP FUNCTION {$funcname} ";
-
- return $this->execute($sql);
}
/**
/**
* Manage functions in a database
*
- * $Id: functions.php,v 1.9 2003/03/17 05:20:30 chriskl Exp $
+ * $Id: functions.php,v 1.10 2003/04/30 06:49:11 chriskl Exp $
*/
// Include application functions
echo "<h2>", htmlspecialchars($_REQUEST['database']), ": {$lang['strfunctions']}: ", htmlspecialchars($_REQUEST['function']), ": {$lang['strdrop']}</h2>\n";
echo "<p>", sprintf($lang['strconfdropfunction'], htmlspecialchars($_REQUEST['function'])), "</p>\n";
+
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
- echo "<input type=hidden name=action value=drop>\n";
- echo "<input type=hidden name=function value=\"", htmlspecialchars($_REQUEST['function']), "\">\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"drop\">\n";
+ echo "<input type=\"hidden\" name=\"function\" value=\"", htmlspecialchars($_REQUEST['function']), "\">\n";
echo $misc->form;
- echo "<input type=submit name=choice value=\"{$lang['stryes']}\"> <input type=submit name=choice value=\"{$lang['strno']}\">\n";
+ // Show cascade drop option if supportd
+ if ($localData->hasDropBehavior()) {
+ echo "<p><input type=\"checkbox\" name=\"cascade\"> {$lang['strcascade']}</p>\n";
+ }
+ echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\"> <input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\">\n";
echo "</form>\n";
}
else {
- $status = $localData->dropFunction($_POST['function']);
+ $status = $localData->dropFunction($_POST['function'], isset($_POST['cascade']));
if ($status == 0)
doDefault($lang['strfunctiondropped']);
else
doCreate();
break;
case 'drop':
- if ($_POST['choice'] == "{$lang['stryes']}") doDrop(false);
+ if (isset($_POST['yes'])) doDrop(false);
else doDefault();
break;
case 'confirm_drop':