* Auto-expand a node in the tree browser if there are no other nodes (Tomasz Pala)
* Add column about fields constraints type + links in table properties page (ioguix)
* Support for built-in Full Text Search (Ivan Zolotukhin)
+* Add alter name, owner & comment on views (ioguix)
Bugs
* Fix inability to assign a field type/domain of a different schema
* Support temporary views per 8.1?
* Allow INSERT and import on views with the appropriate rules.
-* Allow altering of comments
+* - Allow altering of comments (ioguix, with rename & owner)
Sequences
---------
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.302 2007/09/13 05:16:41 xzilla Exp $
+ * $Id: Postgres.php,v 1.303 2007/09/13 14:53:41 ioguix Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
$status = $this->endTransaction();
return ($status == 0) ? 0 : -1;
- }
+ }
+
+ /**
+ * Alters a view
+ * @param $view The name of the view
+ * @param $name The new name for the view
+ * @param $owner The new owner for the view
+ * @param $comment The comment on the view
+ * @return 0 success
+ * @return -1 transaction error
+ * @return -2 owner error
+ * @return -3 rename error
+ * @return -4 comment error
+ * @return -5 get existing view error
+ */
+ function alterView($view, $name, $owner, $comment) {
+ $this->fieldClean($view);
+ $this->fieldClean($name);
+ $this->fieldClean($owner);
+ $this->clean($comment);
+
+ $status = $this->beginTransaction();
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ // Comment
+ $status = $this->setComment('VIEW', $view, '', $comment);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -4;
+ }
+
+ // Owner
+ if ($this->hasAlterTableOwner() && $owner != '') {
+ // Fetch existing owner
+ $data = $this->getView($view);
+ if ($data->recordCount() != 1) {
+ $this->rollbackTransaction();
+ return -5;
+ }
+
+ // If owner has been changed, then do the alteration. We are
+ // careful to avoid this generally as changing owner is a
+ // superuser only function.
+ if ($data->fields['relowner'] != $owner) {
+ $sql = "ALTER TABLE \"{$view}\" OWNER TO \"{$owner}\"";
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -2;
+ }
+ }
+ }
+
+ // Rename (only if name has changed)
+ if ($name != $view) {
+ $sql = "ALTER TABLE \"{$view}\" RENAME TO \"{$name}\"";
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -3;
+ }
+ }
+
+ return $this->endTransaction();
+ }
// Operator functions
/**
* PostgreSQL 8.3 support
*
- * $Id: Postgres83.php,v 1.3 2007/09/13 05:16:42 xzilla Exp $
+ * $Id: Postgres83.php,v 1.4 2007/09/13 14:53:41 ioguix Exp $
*/
include_once('./classes/database/Postgres82.php');
return $this->help_page;
}
+ // Views functions
+
+ /**
+ * Alters a view
+ * @param $view The name of the view
+ * @param $name The new name for the view
+ * @param $owner The new owner for the view
+ * @param $comment The comment on the view
+ * @return 0 success
+ * @return -1 transaction error
+ * @return -2 owner error
+ * @return -3 rename error
+ * @return -4 comment error
+ * @return -5 get existing view error
+ */
+ function alterView($view, $name, $owner, $comment) {
+ $this->fieldClean($view);
+
+ $this->fieldClean($name);
+ $this->fieldClean($owner);
+ $this->clean($comment);
+
+ $status = $this->beginTransaction();
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ // Comment
+ $status = $this->setComment('VIEW', $view, '', $comment);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -4;
+ }
+
+ // Owner
+ if ($owner != '') {
+ // Fetch existing owner
+ $data = $this->getView($view);
+ if ($data->recordCount() != 1) {
+ $this->rollbackTransaction();
+ return -5;
+ }
+
+ // If owner has been changed, then do the alteration. We are
+ // careful to avoid this generally as changing owner is a
+ // superuser only function.
+ if ($data->fields['relowner'] != $owner) {
+ $sql = "ALTER TABLE \"{$view}\" OWNER TO \"{$owner}\"";
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -2;
+ }
+ }
+ }
+
+ // Rename (only if name has changed)
+ if ($name != $view) {
+ $sql = "ALTER VIEW \"{$view}\" RENAME TO \"{$name}\"";
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -3;
+ }
+ }
+
+ return $this->endTransaction();
+ }
+
+ // FTS functions
/**
* Creates a new FTS configuration.
* @param string $cfgname The name of the FTS configuration to create
/**
* Help links for PostgreSQL 7.2 documentation
*
- * $Id: PostgresDoc72.php,v 1.4 2005/02/16 10:27:44 jollytoad Exp $
+ * $Id: PostgresDoc72.php,v 1.5 2007/09/13 14:53:41 ioguix Exp $
*/
include('./help/PostgresDoc71.php');
$this->help_page['pg.aggregate'][1] = 'tutorial-agg.html';
+$this->help_page['pg.view.alter'] = array('sql-createview.html','sql-altertable.html');
?>
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.216 2007/09/13 05:16:42 xzilla Exp $
+ * $Id: english.php,v 1.217 2007/09/13 14:53:41 ioguix Exp $
*/
// Language and character set
$lang['strrenamedupfields'] = 'Rename duplicate fields';
$lang['strdropdupfields'] = 'Drop duplicate fields';
$lang['strerrordupfields'] = 'Error on duplicate fields';
+ $lang['strviewaltered'] = 'View altered.';
+ $lang['strviewalteredbad'] = 'View alteration failed.';
// Sequences
$lang['strsequence'] = 'Sequence';
* French Language file for phpPgAdmin.
* @maintainer Pascal PEYRE [pascal.peyre@cir.fr]
*
- * $Id: french.php,v 1.29 2007/09/10 10:47:58 ioguix Exp $
+ * $Id: french.php,v 1.30 2007/09/13 14:53:41 ioguix Exp $
*/
// Language and character set
$lang['strrenamedupfields'] = 'Renommer les champs dupliqués';
$lang['strdropdupfields'] = 'Ignorer les champs dupliqués';
$lang['strerrordupfields'] = 'Erreur en cas de champs dupliqués';
+ $lang['strviewaltered'] = 'Vue modifiée.';
+ $lang['strviewalteredbad'] = 'Échec lors de la modification de la vue.';
// Sequences
$lang['strsequence'] = 'Séquence';
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.168 2007/09/13 05:16:42 xzilla Exp $
+ * $Id: english.php,v 1.169 2007/09/13 14:53:41 ioguix Exp $
*/
// Language and character set
$lang['strrenamedupfields'] = 'Rename duplicate fields';
$lang['strdropdupfields'] = 'Drop duplicate fields';
$lang['strerrordupfields'] = 'Error on duplicate fields';
+ $lang['strviewaltered'] = 'View altered.';
+ $lang['strviewalteredbad'] = 'View alteration failed.';
// Sequences
$lang['strsequence'] = 'Sequence';
* French Language file for phpPgAdmin.
* @maintainer Pascal PEYRE [pascal.peyre@cir.fr]
*
- * $Id: french.php,v 1.28 2007/09/10 10:47:58 ioguix Exp $
+ * $Id: french.php,v 1.29 2007/09/13 14:53:41 ioguix Exp $
*/
// Language and character set
$lang['strrenamedupfields'] = 'Renommer les champs dupliqués';
$lang['strdropdupfields'] = 'Ignorer les champs dupliqués';
$lang['strerrordupfields'] = 'Erreur en cas de champs dupliqués';
+ $lang['strviewaltered'] = 'Vue modifiée.';
+ $lang['strviewalteredbad'] = 'Échec lors de la modification de la vue.';
// Sequences
$lang['strsequence'] = 'Séquence';
/**
* List views in a database
*
- * $Id: viewproperties.php,v 1.32 2007/09/13 13:41:01 ioguix Exp $
+ * $Id: viewproperties.php,v 1.33 2007/09/13 14:53:41 ioguix Exp $
*/
// Include application functions
}
}
+ function doAlter($confirm = false, $msg = '') {
+ if ($confirm) {
+ global $data, $misc, $lang;
+
+ $misc->printTrail('view');
+ $misc->printTitle($lang['stralter'], 'pg.view.alter');
+ $misc->printMsg($msg);
+
+ // Fetch view info
+ $view = $data->getView($_REQUEST['view']);
+
+ if ($view->recordCount() > 0) {
+ if (!isset($_POST['name'])) $_POST['name'] = $view->fields['relname'];
+ if (!isset($_POST['owner'])) $_POST['owner'] = $view->fields['relowner'];
+ if (!isset($_POST['comment'])) $_POST['comment'] = $view->fields['relcomment'];
+
+ echo "<form action=\"viewproperties.php\" method=\"post\">\n";
+ echo "<table>\n";
+ echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
+ echo "<td class=\"data1\">";
+ echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
+ htmlspecialchars($_POST['name']), "\" /></td></tr>\n";
+
+ $server_info = $misc->getServerInfo();
+ if ($data->hasAlterTableOwner() && $data->isSuperUser($server_info['username'])) {
+
+ // Fetch all users
+ $users = $data->getUsers();
+
+ echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
+ echo "<td class=\"data1\"><select name=\"owner\">";
+ while (!$users->EOF) {
+ $uname = $users->fields['usename'];
+ echo "<option value=\"", htmlspecialchars($uname), "\"",
+ ($uname == $_POST['owner']) ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n";
+ $users->moveNext();
+ }
+ echo "</select></td></tr>\n";
+ }
+
+ echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
+ echo "<td class=\"data1\">";
+ echo "<textarea rows=\"3\" cols=\"32\" name=\"comment\">",
+ htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n";
+ echo "</table>\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
+ echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
+ echo $misc->form;
+ echo "<p><input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
+ echo "</form>\n";
+ }
+ else echo "<p>{$lang['strnodata']}</p>\n";
+ }
+ else{
+ global $data, $lang, $_reload_browser;
+
+ // For databases that don't allow owner change
+ if (!isset($_POST['owner'])) $_POST['owner'] = '';
+ $status = $data->alterView($_POST['view'], $_POST['name'], $_POST['owner'], $_POST['comment']);
+ if ($status == 0) {
+ // If view has been renamed, need to change to the new name and
+ // reload the browser frame.
+ if ($_POST['view'] != $_POST['name']) {
+ // Jump them to the new view name
+ $_REQUEST['view'] = $_POST['name'];
+ // Force a browser reload
+ $_reload_browser = true;
+ }
+ doDefault($lang['strviewaltered']);
+ }
+ else doAlter(true, $lang['strviewalteredbad']);
+ }
+ }
+
function doTree () {
global $misc, $data;
urlencode($lang['strback']), "\">{$lang['strbrowse']}</a></li>\n";
echo "\t<li><a href=\"views.php?action=confselectrows&{$misc->href}&view=", urlencode($_REQUEST['view']),"\">{$lang['strselect']}</a></li>\n";
echo "\t<li><a href=\"views.php?action=confirm_drop&{$misc->href}&view=", urlencode($_REQUEST['view']),"\">{$lang['strdrop']}</a></li>\n";
+ echo "\t<li><a href=\"viewproperties.php?action=confirm_alter&{$misc->href}&view=", urlencode($_REQUEST['view']),"\">{$lang['stralter']}</a></li>\n";
echo "</ul>\n";
}
if (isset($_POST['cancel'])) doDefault();
else doProperties();
break;
+ case 'alter':
+ if (isset($_POST['alter'])) doAlter(false);
+ else doDefault();
+ break;
+ case 'confirm_alter':
+ doAlter(true);
+ break;
case 'drop':
if (isset($_POST['drop'])) doDrop(false);
else doDefault();