* Comment stuff
* Import
* Script execution
-* Create view wizard looks buggy
\ No newline at end of file
+* Create view wizard looks buggy
+* alter function on < 7.2 needs testing
* Automatically uncheck the NULL checkbox when data is typed in the value
field while editing data.
* Show query runtime when executing arbitrary SQL
+* Allow renaming functions when backend supports it
Bugs
* Fix pg_dump output for PostgreSQL 7.0.x and 7.1.x
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: BaseDB.php,v 1.43 2004/04/12 06:30:55 chriskl Exp $
+ * $Id: BaseDB.php,v 1.44 2004/05/09 09:10:04 chriskl Exp $
*/
include_once('./classes/database/ADODB_base.php');
function hasFullExplain() { return false; }
function hasStatsCollector() { return false; }
function hasSchemaDump() { return false; }
+ function hasFunctionRename() { return false; }
+
}
?>
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.199 2004/05/09 06:56:48 chriskl Exp $
+ * $Id: Postgres.php,v 1.200 2004/05/09 09:10:04 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
/**
* Sets the comment for an object in the database
- * @param $obj_type One of 'TABLE' | 'COLUMN' | 'VIEW' | 'SCHEMA' | 'SEQUENCE' | 'TYPE'
+ * @param $obj_type One of 'TABLE' | 'COLUMN' | 'VIEW' | 'SCHEMA' | 'SEQUENCE' | 'TYPE' | 'FUNCTION'
* @param $obj_name The name of the object for which to attach a comment
* @param $table Name of table that $obj_name belongs to. Ignored unless $obj_type is 'TABLE' or 'COLUMN'.
* @param $comment The comment to add
* @return 0 success
*/
-
function setComment($obj_type, $obj_name, $table, $comment) {
- // Make sure we have a valid type
- $types = array('TABLE','COLUMN','VIEW','SCHEMA','SEQUENCE','TYPE');
- if (! in_array($obj_type,$types)) return -1;
-
+ $this->clean($comment);
+
$sql = "COMMENT ON {$obj_type} " ;
switch ($obj_type) {
- case 'TABLE':
- $sql .= "\"{$table}\" IS ";
- break;
- case 'COLUMN':
- $sql .= "\"{$table}\".\"{$obj_name}\" IS ";
- break;
- default:
- $sql .= "\"{$obj_name}\" IS ";
+ case 'TABLE':
+ $sql .= "\"{$table}\" IS ";
+ break;
+ case 'COLUMN':
+ $sql .= "\"{$table}\".\"{$obj_name}\" IS ";
+ break;
+ case 'VIEW':
+ case 'SCHEMA':
+ case 'SEQUENCE':
+ case 'TYPE':
+ $sql .= "\"{$obj_name}\" IS ";
+ break;
+ case 'FUNCTION':
+ $sql .= "{$obj_name} IS ";
+ break;
+ default:
+ // Unknown object type
+ return -1;
}
if ($comment != '')
probin as binary,
proretset,
proiscachable,
- oidvectortypes(pc.proargtypes) AS arguments
+ oidvectortypes(pc.proargtypes) AS arguments,
+ (SELECT description FROM pg_description pd WHERE pc.oid=pd.objoid) AS funccomment
FROM
pg_proc pc, pg_language pl, pg_type pt
WHERE
* so we do it with a drop and a recreate.
* @param $function_oid The OID of the function
* @param $funcname The name of the function to create
+ * @param $newname The new name for the function
* @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
+ * @param $comment The comment on the function
* @return 0 success
* @return -1 transaction error
* @return -2 drop function error
* @return -3 create function error
+ * @return -4 comment error
*/
- function setFunction($function_oid, $funcname, $args, $returns, $definition, $language, $flags, $setof) {
+ function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $comment) {
$status = $this->beginTransaction();
if ($status != 0) return -1;
-
+
+ // Drop existing function
$status = $this->dropFunction($function_oid, false);
if ($status != 0) {
$this->rollbackTransaction();
return -2;
}
- $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, false);
+ // Create function with new name
+ $status = $this->createFunction($newname, $args, $returns, $definition, $language, $flags, $setof, false);
if ($status != 0) {
$this->rollbackTransaction();
return -3;
}
+
+ // Comment on the function
+ $this->fieldClean($newname);
+ $status = $this->setComment('FUNCTION', "\"{$newname}\"({$args})", null, $comment);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -4;
+ }
$status = $this->endTransaction();
return ($status == 0) ? 0 : -1;
function hasOpClasses() { return true; }
function hasUserSessionDefaults() { return false; }
function hasUserRename() { return false; }
+ function hasFunctionRename() { return true; }
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres71.php,v 1.54 2004/05/08 11:34:14 chriskl Exp $
+ * $Id: Postgres71.php,v 1.55 2004/05/09 09:10:04 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
proretset,
proisstrict,
proiscachable,
- oidvectortypes(pc.proargtypes) AS arguments
+ oidvectortypes(pc.proargtypes) AS arguments,
+ (SELECT description FROM pg_description pd WHERE pc.oid=pd.objoid) AS funccomment
FROM
pg_proc pc, pg_language pl
WHERE
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres72.php,v 1.62 2004/05/08 15:21:43 chriskl Exp $
+ * $Id: Postgres72.php,v 1.63 2004/05/09 09:10:04 chriskl Exp $
*/
* Updates (replaces) a function.
* @param $function_oid The OID of the function
* @param $funcname The name of the function to create
+ * @param $newname The new name for the function
* @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
+ * @param $comment The comment on the function
* @return 0 success
+ * @return -1 transaction error
+ * @return -2 commenting error
+ * @return -3 rename error
*/
- function setFunction($function_oid, $funcname, $args, $returns, $definition, $language, $flags, $setof) {
- return $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
+ function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $comment) {
+ // Begin a transaction
+ $status = $this->beginTransaction();
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ // Replace the existing function
+ $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ // Comment on the function
+ $this->fieldClean($funcname);
+ $status = $this->setComment('FUNCTION', "\"{$funcname}\"({$args})", null, $comment);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -2;
+ }
+
+ // Rename the function, if necessary
+ if ($funcname != $newname && $this->hasFunctionRename()) {
+ $this->fieldClean($newname);
+ $sql = "ALTER FUNCTION \"{$funcname}\"({$args}) RENAME TO \"{$newname}\"";
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -3;
+ }
+ }
+
+ return $this->endTransaction();
}
// Type functions
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.100 2004/05/09 04:31:42 chriskl Exp $
+ * $Id: Postgres73.php,v 1.101 2004/05/09 09:10:04 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
proisstrict,
provolatile,
prosecdef,
- oidvectortypes(pc.proargtypes) AS arguments
+ oidvectortypes(pc.proargtypes) AS arguments,
+ pg_catalog.obj_description(pc.oid, 'pg_proc') AS funccomment
FROM
pg_catalog.pg_proc pc, pg_catalog.pg_language pl
WHERE
function hasUserSessionDefaults() { return true; }
function hasVariables() { return true; }
function hasFullExplain() { return true; }
+ function hasFunctionRename() { return false; }
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres74.php,v 1.27 2004/03/31 03:30:41 chriskl Exp $
+ * $Id: Postgres74.php,v 1.28 2004/05/09 09:10:04 chriskl Exp $
*/
include_once('./classes/database/Postgres73.php');
function hasGrantOption() { return true; }
function hasDomainConstraints() { return true; }
function hasUserRename() { return true; }
+ function hasFunctionRename() { return true; }
function hasSchemaDump() { return true; }
}
/**
* Manage functions in a database
*
- * $Id: functions.php,v 1.29 2004/05/08 14:45:09 chriskl Exp $
+ * $Id: functions.php,v 1.30 2004/05/09 09:10:04 chriskl Exp $
*/
// Include application functions
*/
function doSaveEdit() {
global $data, $lang;
+
+ // If the backend does not support renaming functions...
+ if (!$data->hasFunctionRename()) $_POST['formFunction'] = $_POST['original_function'];
- $status = $data->setFunction($_POST['function_oid'], $_POST['original_function'], $_POST['original_arguments'],
- $_POST['original_returns'], $_POST['formDefinition'],
- $_POST['original_lang'], $_POST['formProperties'], isset($_POST['original_setof']), true);
+ $status = $data->setFunction($_POST['function_oid'], $_POST['original_function'], $_POST['formFunction'],
+ $_POST['original_arguments'],
+ $_POST['original_returns'], $_POST['formDefinition'],
+ $_POST['original_lang'], $_POST['formProperties'],
+ isset($_POST['original_setof']), $_POST['formComment']);
if ($status == 0)
doProperties($lang['strfunctionupdated']);
else
// Initialise variables
if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = $fndata->f[$data->fnFields['fndef']];
if (!isset($_POST['formProperties'])) $_POST['formProperties'] = $data->getFunctionProperties($fndata->f);
+ if (!isset($_POST['formFunction'])) $_POST['formFunction'] = $fndata->f[$data->fnFields['fnname']];
+ if (!isset($_POST['formComment'])) $_POST['formComment'] = $fndata->f['funccomment'];
$func_full = $fndata->f[$data->fnFields['fnname']] . "(". $fndata->f[$data->fnFields['fnarguments']] .")";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo "<tr>\n";
- echo "<td class=\"data1\">", $misc->printVal($fndata->f[$data->fnFields['fnname']]), "\n";
+ echo "<td class=\"data1\">";
echo "<input type=\"hidden\" name=\"original_function\" value=\"", htmlspecialchars($fndata->f[$data->fnFields['fnname']]),"\" />\n";
+ // If we're 7.4 or above, we can rename functions
+ if ($data->hasFunctionRename()) {
+ echo "<input name=\"formFunction\" style=\"width: 100%\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['formFunction']), "\" />";
+ }
+ else
+ echo $misc->printVal($fndata->f[$data->fnFields['fnname']]);
echo "</td>\n";
echo "<td class=\"data1\">", $misc->printVal($fndata->f[$data->fnFields['fnarguments']]), "\n";
echo "<tr><th class=\"data required\" colspan=\"8\">{$lang['strdefinition']}</th></tr>\n";
echo "<tr><td class=\"data1\" colspan=\"8\"><textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\" wrap=\"virtual\">",
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\"><input name=\"formComment\" style=\"width: 100%\" value=\"",
+ htmlspecialchars($_POST['formComment']), "\" /></td></tr>\n";
// Display function properies
if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) {
echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strproperties']}</th></tr>\n";
}
echo "</td></tr>\n";
}
+ echo "</td></tr>\n";
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
echo "<input type=\"hidden\" name=\"function\" value=\"", htmlspecialchars($_REQUEST['function']), "\" />\n";
echo "<td class=\"data1\">", $misc->printVal($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\">", $misc->printVal($funcdata->f[$data->fnFields['fndef']]), "</td></tr>\n";
+ // Show comment
+ echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strcomment']}</th></tr>\n";
+ echo "<tr><td class=\"data1\" colspan=\"4\">", $misc->printVal($funcdata->f['funccomment']), "</td></tr>\n";
+ // Show flags
if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) {
// Fetch an array of the function properties
$funcprops = $data->getFunctionProperties($funcdata->f);