/**
* Manage databases within a server
*
- * $Id: all_db.php,v 1.44 2006/06/17 12:57:36 xzilla Exp $
+ * $Id: all_db.php,v 1.45 2006/11/19 21:33:13 xzilla Exp $
*/
// Include application functions
}
echo "</select></td></tr>\n";
}
+ if ($data->hasSharedComments()){
+ $rs = $data->getDatabaseComment($_REQUEST['alterdatabase']);
+ $comment = isset($rs->fields['description']) ? $rs->fields['description'] : '';
+ echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
+ echo "<td class=\"data1\">";
+ echo "<textarea rows=\"3\" cols=\"32\" name=\"dbcomment\" wrap=\"virtual\">",
+ htmlspecialchars($comment), "</textarea></td></tr>\n";
+ }
echo "</table>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
echo $misc->form;
echo "</form>\n";
}
else {
- //all versions that support the alter database functionality (starting 7.4) support renaming a db
$newOwner = isset($_POST['owner']) ? $_POST['owner'] : '';
- if ($data->AlterDatabase($_POST['oldname'], $_POST['newname'], $newOwner) == 0) {
+ if ($data->AlterDatabase($_POST['oldname'], $_POST['newname'], $newOwner, $_POST['dbcomment']) == 0) {
$_reload_browser = true;
doDefault($lang['strdatabasealtered']);
}
$_POST['formEncoding'] = '';
}
if (!isset($_POST['formSpc'])) $_POST['formSpc'] = '';
+ if (!isset($_POST['formComment'])) $_POST['formComment'] = '';
// Fetch all tablespaces from the database
if ($data->hasTablespaces()) $tablespaces = $data->getTablespaces();
}
echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
}
-
+
+ // Comments (if available)
+ if ($data->hasSharedComments()) {
+ echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
+ echo "\t\t<td><textarea name=\"formComment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">",
+ htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
+ }
+
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
echo $misc->form;
// Default tablespace to null if it isn't set
if (!isset($_POST['formSpc'])) $_POST['formSpc'] = null;
+ // Default comment to blank if it isn't set
+ if (!isset($_POST['formComment'])) $_POST['formComment'] = null;
+
// Check that they've given a name and a definition
if ($_POST['formName'] == '') doCreate($lang['strdatabaseneedsname']);
else {
- $status = $data->createDatabase($_POST['formName'], $_POST['formEncoding'], $_POST['formSpc']);
+ $status = $data->createDatabase($_POST['formName'], $_POST['formEncoding'], $_POST['formSpc'], $_POST['formComment']);
if ($status == 0) {
$_reload_browser = true;
doDefault($lang['strdatabasecreated']);
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.291 2006/11/01 00:51:19 xzilla Exp $
+ * $Id: Postgres.php,v 1.292 2006/11/19 21:33:13 xzilla Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
* @param $encoding Encoding of the database
* @param $tablespace (optional) The tablespace name
* @return 0 success
+ * @return -1 tablespace error
+ * @return -2 comment error
*/
- function createDatabase($database, $encoding, $tablespace = '') {
+ function createDatabase($database, $encoding, $tablespace = '', $comment = '') {
$this->fieldClean($database);
$this->clean($encoding);
$this->fieldClean($tablespace);
+ $this->fieldClean($comment);
if ($encoding == '') {
$sql = "CREATE DATABASE \"{$database}\"";
}
if ($tablespace != '' && $this->hasTablespaces()) $sql .= " TABLESPACE \"{$tablespace}\"";
-
- return $this->execute($sql);
+
+ $status = $this->execute($sql);
+ if ($status != 0) return -1;
+
+ if ($comment != '' && $this->hasSharedComments()) {
+ $status = $this->setComment('DATABASE',$database,'',$comment);
+ if ($status != 0) return -2;
+ }
+
+ return 0;
+
}
/**
case 'COLUMN':
$sql .= "\"{$table}\".\"{$obj_name}\" IS ";
break;
- case 'VIEW':
+ case 'DATABASE';
+ case 'ROLE';
case 'SCHEMA':
case 'SEQUENCE':
+ case 'TABLESPACE';
case 'TYPE':
+ case 'VIEW':
$sql .= "\"{$obj_name}\" IS ";
break;
case 'FUNCTION':
function hasPreparedXacts() { return false; }
function hasDisableTriggers() { return false; }
function hasAlterAggregate() { return false; }
+ function hasSharedComments() {return false;}
}
?>
/**
* PostgreSQL 8.0 support
*
- * $Id: Postgres80.php,v 1.19 2006/05/19 07:17:30 chriskl Exp $
+ * $Id: Postgres80.php,v 1.20 2006/11/19 21:33:13 xzilla Exp $
*/
include_once('./classes/database/Postgres74.php');
* @param $spcloc The directory in which to create the tablespace
* @return 0 success
*/
- function createTablespace($spcname, $spcowner, $spcloc) {
+ function createTablespace($spcname, $spcowner, $spcloc, $comment='') {
$this->fieldClean($spcname);
$this->clean($spcloc);
+ $this->clean($comment);
$sql = "CREATE TABLESPACE \"{$spcname}\"";
$sql .= " LOCATION '{$spcloc}'";
- return $this->execute($sql);
+ $status = $this->execute($sql);
+ if ($status != 0) return -1;
+
+ if ($comment != '' && $this->hasSharedComments()) {
+ $status = $this->setComment('TABLESPACE',$spcname,'',$comment);
+ if ($status != 0) return -2;
+ }
+
+ return 0;
+
}
/**
* @return -1 transaction error
* @return -2 owner error
* @return -3 rename error
+ * @return -4 comment error
*/
- function alterTablespace($spcname, $name, $owner) {
+ function alterTablespace($spcname, $name, $owner, $comment='') {
$this->fieldClean($spcname);
$this->fieldClean($name);
$this->fieldClean($owner);
return -3;
}
}
+
+ // Set comment if it has changed
+ if (trim($comment) != '' && $this->hasSharedComments()) {
+ $status = $this->setComment('TABLESPACE',$spcname,'',$comment);
+ if ($status != 0) return -4;
+ }
return $this->endTransaction();
}
/**
* PostgreSQL 8.2 support
*
- * $Id: Postgres82.php,v 1.2 2006/11/01 00:50:17 xzilla Exp $
+ * $Id: Postgres82.php,v 1.3 2006/11/19 21:33:13 xzilla Exp $
*/
include_once('./classes/database/Postgres81.php');
return $this->help_page;
}
+ // Database functions
+ /**
+ * Return all database available on the server
+ * @return A list of databases, sorted alphabetically
+ */
+ function getDatabases($currentdatabase = NULL) {
+ global $conf, $misc;
+
+ $server_info = $misc->getServerInfo();
+
+ if (isset($conf['owned_only']) && $conf['owned_only'] && !$this->isSuperUser($server_info['username'])) {
+ $username = $server_info['username'];
+ $this->clean($username);
+ $clause = " AND pu.usename='{$username}'";
+ }
+ else $clause = '';
+
+ if ($currentdatabase != NULL)
+ $orderby = "ORDER BY pdb.datname = '{$currentdatabase}' DESC, pdb.datname";
+ else
+ $orderby = "ORDER BY pdb.datname";
+
+ if (!$conf['show_system'])
+ $where = ' AND NOT pdb.datistemplate';
+ else
+ $where = ' AND pdb.datallowconn';
+
+ $sql = "SELECT pdb.datname AS datname, pr.rolname AS datowner, pg_encoding_to_char(encoding) AS datencoding,
+ (SELECT description FROM pg_catalog.pg_shdescription pd WHERE pdb.oid=pd.objoid) AS datcomment,
+ (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pdb.dattablespace) AS tablespace,
+ pg_catalog.pg_database_size(pdb.oid) as dbsize
+ FROM pg_catalog.pg_database pdb LEFT JOIN pg_catalog.pg_roles pr ON (pdb.datdba = pr.oid)
+ WHERE true
+ {$where}
+ {$clause}
+ {$orderby}";
+
+ return $this->selectSet($sql);
+ }
+
+ /**
+ * Alters a database
+ * the multiple return vals are for postgres 8+ which support more functionality in alter database
+ * @param $dbName The name of the database
+ * @param $newName new name for the database
+ * @param $newOwner The new owner for the database
+ * @return 0 success
+ * @return -1 transaction error
+ * @return -2 owner error
+ * @return -3 rename error
+ * @return -4 comment error
+ */
+ function alterDatabase($dbName, $newName, $newOwner = '',$comment = '')
+ {
+ //ignore $newowner, not supported pre 8.0
+ //ignore $comment, not supported pre 8.2
+ $this->clean($dbName);
+ $this->clean($newName);
+
+ $status = $this->alterDatabaseRename($dbName, $newName);
+ if ($status != 0) return -3;
+
+ if (trim($comment) != '' ) {
+ $status = $this->setComment('DATABASE',$dbName,'', $comment);
+ if ($status != 0) return -4;
+ }
+ else return 0;
+ }
+
+ /**
+ * Return the database comment of a db from the shared description table
+ * @param string $database the name of the database to get the comment for
+ * @return recordset of the db comment info
+ */
+ function getDatabaseComment($database) {
+ $this->clean($database);
+ $sql = "SELECT description FROM pg_catalog.pg_database JOIN pg_catalog.pg_shdescription ON (oid=objoid) WHERE pg_database.datname = '{$database}' ";
+ return $this->selectSet($sql);
+ }
+
+ // Tablespace functions
+
+ /**
+ * Retrieves information for all tablespaces
+ * @param $all Include all tablespaces (necessary when moving objects back to the default space)
+ * @return A recordset
+ */
+ function getTablespaces($all = false) {
+ global $conf;
+
+ $sql = "SELECT spcname, pg_catalog.pg_get_userbyid(spcowner) AS spcowner, spclocation,
+ (SELECT description FROM pg_catalog.pg_shdescription pd WHERE pg_tablespace.oid=pd.objoid) AS spccomment
+ FROM pg_catalog.pg_tablespace";
+
+ if (!$conf['show_system'] && !$all) {
+ $sql .= " WHERE spcname NOT LIKE 'pg\\\\_%'";
+ }
+
+ $sql .= " ORDER BY spcname";
+
+ return $this->selectSet($sql);
+ }
+
+ /**
+ * Retrieves a tablespace's information
+ * @return A recordset
+ */
+ function getTablespace($spcname) {
+ $this->clean($spcname);
+
+ $sql = "SELECT spcname, pg_catalog.pg_get_userbyid(spcowner) AS spcowner, spclocation,
+ (SELECT description FROM pg_catalog.pg_shdescription pd WHERE pg_tablespace.oid=pd.objoid) AS spccomment
+ FROM pg_catalog.pg_tablespace WHERE spcname='{$spcname}'";
+
+ return $this->selectSet($sql);
+ }
+
+ // Capabilities
+ function hasSharedComments() {return true;}
}
?>
/**
* Manage tablespaces in a database cluster
*
- * $Id: tablespaces.php,v 1.9 2005/10/18 03:45:16 chriskl Exp $
+ * $Id: tablespaces.php,v 1.10 2006/11/19 21:33:13 xzilla Exp $
*/
// Include application functions
if (!isset($_POST['name'])) $_POST['name'] = $tablespace->f['spcname'];
if (!isset($_POST['owner'])) $_POST['owner'] = $tablespace->f['spcowner'];
+ if (!isset($_POST['comment'])) {
+ $_POST['comment'] = ($data->hasSharedComments()) ? $tablespace->f['spccomment'] : '';
+ }
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo $misc->form;
($uname == $_POST['owner']) ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n";
$users->moveNext();
}
- echo "</select></td></tr>\n";
+ echo "</select></td></tr>\n";
+ if ($data->hasSharedComments()){
+ echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
+ echo "<td class=\"data1\">";
+ echo "<textarea rows=\"3\" cols=\"32\" name=\"comment\" wrap=\"virtual\">",
+ htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n";
+ }
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
echo "<input type=\"hidden\" name=\"tablespace\" value=\"", htmlspecialchars($_REQUEST['tablespace']), "\" />\n";
if (trim($_POST['name']) == '')
doAlter($lang['strtablespaceneedsname']);
else {
- $status = $data->alterTablespace($_POST['tablespace'], $_POST['name'], $_POST['owner']);
+ $status = $data->alterTablespace($_POST['tablespace'], $_POST['name'], $_POST['owner'], $_POST['comment']);
if ($status == 0) {
// If tablespace has been renamed, need to change to the new name
if ($_POST['tablespace'] != $_POST['name']) {
if (!isset($_POST['formSpcname'])) $_POST['formSpcname'] = '';
if (!isset($_POST['formOwner'])) $_POST['formOwner'] = $server_info['username'];
if (!isset($_POST['formLoc'])) $_POST['formLoc'] = '';
+ if (!isset($_POST['formComment'])) $_POST['formComment'] = '';
// Fetch all users
$users = $data->getUsers();
echo "\t\t</select></td>\n\t</tr>\n";
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strlocation']}</th>\n";
echo "\t\t<td class=\"data1\"><input size=\"32\" name=\"formLoc\" value=\"", htmlspecialchars($_POST['formLoc']), "\" /></td>\n\t</tr>\n";
+ // Comments (if available)
+ if ($data->hasSharedComments()) {
+ echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
+ echo "\t\t<td><textarea name=\"formComment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">",
+ htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
+ }
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
doCreate($lang['strtablespaceneedsname']);
elseif (trim($_POST['formLoc']) == '')
doCreate($lang['strtablespaceneedsloc']);
- else {
- $status = $data->createTablespace($_POST['formSpcname'], $_POST['formOwner'], $_POST['formLoc']);
+ else {
+ // Default comment to blank if it isn't set
+ if (!isset($_POST['formComment'])) $_POST['formComment'] = null;
+
+ $status = $data->createTablespace($_POST['formSpcname'], $_POST['formOwner'], $_POST['formLoc'], $_POST['formComment']);
if ($status == 0)
doDefault($lang['strtablespacecreated']);
else
'title' => $lang['stractions']
)
);
+
+ if ($data->hasSharedComments()) {
+ $columns['comment'] = array(
+ 'title' => $lang['strcomment'],
+ 'field' => 'spccomment',
+ );
+ }
+
+
$actions = array(
'alter' => array(