* Don't offer owner change feature if user is not superuser
* check use of apostrophes, etc. in tree menu
+* Fix all uses of setComment that do double escaping
+
- Nicola Soranzo
- Oliver Meyer & Sven Kiera (Table icons link to browse table)
- Bryan Encina (SQL window improvements, bug fixes)
+- Dan Boren (Object comments)
Features
* Add CACHE and CYCLE parameters in sequence creation
+* View, add, edit and delete comments on views, schemas and columns (Dan Boren)
+
+Version 3.3.1
+-------------
Bugs
* Fix table stats for <= 7.2
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.185 2004/03/12 01:12:09 soranzo Exp $
+ * $Id: Postgres.php,v 1.186 2004/03/12 08:56:53 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
var $dbFields = array('dbname' => 'datname', 'dbcomment' => 'description', 'encoding' => 'encoding', 'owner' => 'owner');
var $tbFields = array('tbname' => 'tablename', 'tbowner' => 'tableowner', 'tbcomment' => 'tablecomment');
- var $vwFields = array('vwname' => 'viewname', 'vwowner' => 'viewowner', 'vwdef' => 'definition');
+ var $vwFields = array('vwname' => 'viewname', 'vwowner' => 'viewowner', 'vwdef' => 'definition', 'vwcomment' => 'comment');
var $uFields = array('uname' => 'usename', 'usuper' => 'usesuper', 'ucreatedb' => 'usecreatedb', 'uexpires' => 'valuntil');
var $grpFields = array('groname' => 'groname', 'grolist' => 'grolist');
var $sqFields = array('seqname' => 'relname', 'seqowner' => 'usename', 'lastvalue' => 'last_value', 'incrementby' => 'increment_by', 'maxvalue' => 'max_value', 'minvalue'=> 'min_value', 'cachevalue' => 'cache_value', 'logcount' => 'log_cnt', 'iscycled' => 'is_cycled', 'iscalled' => 'is_called' );
$sql .= "CREATE TABLE \"{$t->f['tablename']}\" (\n";
// Output all table columns
+ $col_comments_sql = ''; // Accumulate comments on columns
$num = $atts->recordCount() + $cons->recordCount();
$i = 1;
while (!$atts->EOF) {
if ($i < $num) $sql .= ",\n";
else $sql .= "\n";
+ // Does this column have a comment?
+ if ($atts->f['comment'] !== null) {
+ $this->clean($atts->f['comment']);
+ $col_comments_sql .= "COMMENT ON COLUMN \"{$t->f['tablename']}\".\"{$atts->f['attname']}\" IS '{$atts->f['comment']}';\n";
+ }
+
$atts->moveNext();
$i++;
}
// Comment
if ($t->f['tablecomment'] !== null) {
- $this->clean($t->f['tablecomment']);
- $sql .= "\n-- Comment\n\n";
- $sql .= "COMMENT ON TABLE \"{$t->f['tablename']}\" IS '{$t->f['tablecomment']}';\n";
+ $this->clean($t->f['tablecomment']);
+ $sql .= "\n-- Comment\n\n";
+ $sql .= "COMMENT ON TABLE \"{$t->f['tablename']}\" IS '{$t->f['tablecomment']}';\n";
}
+ // Add comments on columns, if any
+ if ($col_comments_sql != '') $sql .= $col_comments_sql;
+
// Privileges
$privs = &$this->getPrivileges($table, 'table');
if (!is_array($privs)) {
$this->clean($table);
$sql = "SELECT pc.relname AS tablename,
- pg_get_userbyid(pc.relowner) AS tableowner,
- (SELECT description FROM pg_description pd WHERE pc.oid=pd.objoid) AS tablecomment
- FROM pg_class pc
- WHERE pc.relname='{$table}'";
+ pg_get_userbyid(pc.relowner) AS tableowner,
+ (SELECT description FROM pg_description pd
+ WHERE pc.oid=pd.objoid AND objsubid = 0) AS tablecomment
+ FROM pg_class pc
+ WHERE pc.relname='{$table}'";
return $this->selectSet($sql);
}
* @param $name The new name for the column
* @param $notnull (boolean) True if not null, false otherwise
* @param $default The new default for the column
- * @param $olddefault THe old default for the column
+ * @param $olddefault The old default for the column
+ * @param $comment Comment for the column
* @return 0 success
* @return -1 set not null error
* @return -2 set default error
* @return -3 rename column error
+ * @return -4 comment error
*/
- function alterColumn($table, $column, $name, $notnull, $default, $olddefault) {
+ function alterColumn($table, $column, $name, $notnull, $default, $olddefault, $comment) {
$this->beginTransaction();
// @@ NEED TO HANDLE "NESTED" TRANSACTION HERE
}
}
+ $status = $this->setComment('COLUMN', $column, $table, $comment);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -4;
+ }
+
return $this->endTransaction();
}
* @param $notnull An array of not null
* @param $default An array of default values
* @param $withoutoids True if WITHOUT OIDS, false otherwise
+ * @param $comment Table comment
* @return 0 success
* @return -1 no fields supplied
*/
- function createTable($name, $fields, $field, $type, $length, $notnull, $default, $withoutoids) {
+ function createTable($name, $fields, $field, $type, $length, $notnull, $default, $withoutoids, $colcomment, $tblcomment) {
$this->fieldClean($name);
+ $this->fieldClean($tblcomment);
+
+ $status = $this->beginTransaction();
+ if ($status != 0) return -1;
$found = false;
+ $comment_sql = ''; //Accumulate comments for the columns
$sql = "CREATE TABLE \"{$name}\" (";
for ($i = 0; $i < $fields; $i++) {
$this->fieldClean($field[$i]);
$this->clean($type[$i]);
$this->clean($length[$i]);
+ $this->clean($colcomment[$i]);
// Skip blank columns - for user convenience
if ($field[$i] == '' || $type[$i] == '') continue;
if ($default[$i] != '') $sql .= " DEFAULT {$default[$i]}";
if ($i != $fields - 1) $sql .= ", ";
+ if ($colcomment[$i] != '') $comment_sql .= "COMMENT ON COLUMN \"{$name}\".\"{$field[$i]}\" IS '{$colcomment[$i]}';\n";
+
$found = true;
}
if ($this->hasWithoutOIDs() && $withoutoids)
$sql .= ' WITHOUT OIDS';
- return $this->execute($sql);
+ $status = $this->execute($sql);
+ if ($status) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ if ($tblcomment != '') {
+ $status = $this->setComment('TABLE', '', $name, $tblcomment);
+ if ($status) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+ }
+
+ if ($comment_sql != '') {
+ $status = $this->execute($comment_sql);
+ if ($status) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+ }
+ return $this->endTransaction();
+
}
/**
}
// Comment
- $sql = "COMMENT ON TABLE \"{$table}\" IS ";
- if ($comment == '') $sql .= 'NULL';
- else $sql .= "'{$comment}'";
-
- $status = $this->execute($sql);
+ $status = $this->setComment('TABLE', '', $table, $comment);
if ($status != 0) {
$this->rollbackTransaction();
return -4;
* @param $length The optional size of the column (ie. 30 for varchar(30))
* @return 0 success
*/
- function addColumn($table, $column, $type, $length) {
+ function addColumn($table, $column, $type, $length, $comment) {
$this->fieldClean($table);
$this->fieldClean($column);
$this->clean($type);
$this->clean($length);
+ $this->clean($comment);
if ($length == '')
$sql = "ALTER TABLE \"{$table}\" ADD COLUMN \"{$column}\" {$type}";
$sql = "ALTER TABLE \"{$table}\" ADD COLUMN \"{$column}\" {$type}({$length})";
}
}
- return $this->execute($sql);
+
+ $status = $this->beginTransaction();
+ if ($status != 0) return -1;
+
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ $status = $this->setComment('COLUMN', $column, $table, $comment);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ return $this->endTransaction();
}
/**
return $this->execute($sql);
}
+ /**
+ * Sets the comment for an object in the database
+ * @param $obj_type One of 'TABLE' | 'COLUMN' | 'VIEW' | 'SCHEMA' | 'SEQUENCE' | 'TYPE'
+ * @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) {
+ $this->clean($obj_type);
+ $this->fieldClean($obj_name);
+ $this->fieldClean($table);
+ $this->clean($comment);
+
+ // Make sure we have a valid type
+ $types = array('TABLE','COLUMN','VIEW','SCHEMA','SEQUENCE','TYPE');
+ if (! in_array($obj_type,$types)) return -1;
+
+ $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 ";
+ }
+
+ if ($comment != '')
+ $sql .= "'{$comment}';";
+ else
+ $sql .= 'NULL;';
+
+ return $this->execute($sql);
+
+ }
+
/**
* Grabs a list of indexes for a table
* @param $table The name of a table whose indexes to retrieve
*/
function &getViews() {
global $conf;
+
+ $where = "WHERE (c.relkind = 'v'::\"char\")";
if (!$conf['show_system'])
- $where = "WHERE viewname NOT LIKE 'pg\\\\_%'";
- else $where = '';
+ $where .= " AND (c.relname NOT LIKE 'pg\\\\_%')";
- $sql = "SELECT viewname, viewowner FROM pg_views {$where} ORDER BY viewname";
+ $sql = "SELECT viewname, viewowner, description as comment
+ FROM pg_class c
+ JOIN pg_views v ON ((v.viewname = c.relname) AND (viewowner = pg_get_userbyid(c.relowner)))
+ LEFT JOIN pg_description d ON (d.objoid = c.oid)
+ {$where}
+ ORDER BY c.relname";
return $this->selectSet($sql);
}
function &getView($view) {
$this->clean($view);
- $sql = "SELECT viewname, viewowner, definition FROM pg_views WHERE viewname='$view'";
-
+ $sql = "SELECT viewname, viewowner, definition, description as comment
+ FROM pg_class c
+ JOIN pg_views v ON ((v.viewname = c.relname) AND (viewowner = pg_get_userbyid(c.relowner)))
+ LEFT JOIN pg_description d ON (d.objoid = c.oid)
+ WHERE (c.relname = '$view')";
return $this->selectSet($sql);
}
* @param $replace True to replace the view, false otherwise
* @return 0 success
*/
- function createView($viewname, $definition, $replace) {
+ function createView($viewname, $definition, $replace, $comment) {
+ $status = $this->beginTransaction();
+ if ($status != 0) return -1;
+
$this->fieldClean($viewname);
+ $this->clean($comment);
+
// Note: $definition not cleaned
$sql = "CREATE ";
if ($replace) $sql .= "OR REPLACE ";
$sql .= "VIEW \"{$viewname}\" AS {$definition}";
- return $this->execute($sql);
+ $status = $this->execute($sql);
+ if ($status) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ if ($comment != '') {
+ $status = $this->setComment('VIEW', $viewname, '', $comment);
+ if ($status) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+ }
+
+ return $this->endTransaction();
}
/**
* @return -1 transaction error
* @return -2 drop view error
* @return -3 create view error
+ * @return -4 comment error
*/
- function setView($viewname, $definition) {
+ function setView($viewname, $definition, $comment) {
$status = $this->beginTransaction();
if ($status != 0) return -1;
return -2;
}
- $status = $this->createView($viewname, $definition, false);
+ $status = $this->createView($viewname, $definition, false, $comment);
if ($status != 0) {
$this->rollbackTransaction();
return -3;
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres72.php,v 1.58 2004/03/06 11:30:00 chriskl Exp $
+ * $Id: Postgres72.php,v 1.59 2004/03/12 08:56:54 chriskl Exp $
*/
a.attname,
format_type(a.atttypid, a.atttypmod) as type, a.atttypmod,
a.attnotnull, a.atthasdef, adef.adsrc,
- -1 AS attstattarget, a.attstorage, t.typstorage, false AS attisserial
+ -1 AS attstattarget, a.attstorage, t.typstorage, false AS attisserial,
+ description as comment
FROM
pg_attribute a LEFT JOIN pg_attrdef adef
ON a.attrelid=adef.adrelid AND a.attnum=adef.adnum
LEFT JOIN pg_type t ON a.atttypid=t.oid
+ LEFT JOIN pg_description d ON (a.attrelid = d.objoid AND a.attnum = d.objsubid)
WHERE
a.attrelid = (SELECT oid FROM pg_class WHERE relname='{$table}')
AND a.attnum > 0
a.attname,
format_type(a.atttypid, a.atttypmod) as type, a.atttypmod,
a.attnotnull, a.atthasdef, adef.adsrc,
- -1 AS attstattarget, a.attstorage, t.typstorage
+ -1 AS attstattarget, a.attstorage, t.typstorage,
+ description as comment
FROM
pg_attribute a LEFT JOIN pg_attrdef adef
ON a.attrelid=adef.adrelid AND a.attnum=adef.adnum
LEFT JOIN pg_type t ON a.atttypid=t.oid
+ LEFT JOIN pg_description d ON (a.attrelid = d.objoid AND a.attnum = d.objsubid)
WHERE
a.attrelid = (SELECT oid FROM pg_class WHERE relname='{$table}')
AND a.attname = '{$field}'
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.90 2004/02/14 04:21:03 chriskl Exp $
+ * $Id: Postgres73.php,v 1.91 2004/03/12 08:56:54 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
var $uFields = array('uname' => 'usename', 'usuper' => 'usesuper', 'ucreatedb' => 'usecreatedb', 'uexpires' => 'valuntil', 'udefaults' => 'useconfig');
- var $nspFields = array('nspname' => 'nspname', 'nspowner' => 'nspowner');
+ var $nspFields = array('nspname' => 'nspname', 'nspowner' => 'nspowner', 'nspcomment' => 'comment');
var $conFields = array('conname' => 'conname', 'conowner' => 'conowner');
// Store the current schema
if (!$conf['show_system']) $and = "AND nspname NOT LIKE 'pg\\\\_%'";
else $and = '';
- $sql = "SELECT pn.nspname, pu.usename AS nspowner FROM pg_catalog.pg_namespace pn, pg_catalog.pg_user pu
+ $sql = "SELECT pn.nspname, pu.usename AS nspowner, pg_catalog.obj_description(pn.oid, 'pg_namespace') AS comment
+ FROM pg_catalog.pg_namespace pn, pg_catalog.pg_user pu
WHERE pn.nspowner = pu.usesysid
- {$and}ORDER BY nspname";
+ {$and} ORDER BY nspname";
return $this->selectSet($sql);
}
*/
function &getSchemaByName($schema) {
$this->clean($schema);
- $sql = "SELECT * FROM pg_catalog.pg_namespace WHERE nspname='{$schema}'";
- return $this->selectRow($sql);
+ $sql = "SELECT nspname, nspowner,nspacl, pg_catalog.obj_description(pn.oid, 'pg_namespace') as comment
+ FROM pg_catalog.pg_namespace pn
+ WHERE nspname='{$schema}'";
+ return $this->selectSet($sql);
}
/**
* @param $authorization (optional) If omitted, defaults to current user.
* @return 0 success
*/
- function createSchema($schemaname, $authorization = '') {
+ function createSchema($schemaname, $authorization = '', $comment = '') {
$this->fieldClean($schemaname);
$this->fieldClean($authorization);
+ $this->clean($comment);
$sql = "CREATE SCHEMA \"{$schemaname}\"";
if ($authorization != '') $sql .= " AUTHORIZATION \"{$authorization}\"";
- return $this->execute($sql);
+
+ $status = $this->beginTransaction();
+ if ($status != 0) return -1;
+
+ // Create the new schema
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ // Set the comment
+ if ($comment != '') {
+ $status = $this->setComment('SCHEMA', $schemaname, '', $comment);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+ }
+ return $this->endTransaction();
}
/**
return $this->execute($sql);
}
+ /**
+ * Updates a schema.
+ * @param $schemaname The name of the schema to drop
+ * @param $comment The new comment for this schema
+ * @return 0 success
+ */
+ function updateSchema($schemaname, $comment) {
+ $this->fieldClean($schemaname);
+ $this->fieldClean($comment);
+ return $this->setComment('SCHEMA', $schemaname, '', $comment);
+ }
+
/**
* Returns all available variable information.
* @return A recordset
AND pd.refobjsubid=a.attnum
AND pd.deptype='i'
AND pc.relkind='S'
- ) IS NOT NULL AS attisserial
+ ) IS NOT NULL AS attisserial,
+ pg_catalog.col_description(a.attrelid, a.attnum) AS comment
FROM
pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef
a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod) as type, a.atttypmod,
a.attnotnull, a.atthasdef, adef.adsrc,
- a.attstattarget, a.attstorage, t.typstorage
+ a.attstattarget, a.attstorage, t.typstorage,
+ pg_catalog.col_description(a.attrelid, a.attnum) AS comment
FROM
pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef
ON a.attrelid=adef.adrelid
* @return All views
*/
function getViews() {
- $sql = "SELECT viewname, viewowner FROM pg_catalog.pg_views
- WHERE schemaname='{$this->_schema}' ORDER BY viewname";
+ $sql = "SELECT c.relname AS viewname, pg_catalog.pg_get_userbyid(c.relowner) AS viewowner,
+ pg_catalog.obj_description(c.oid, 'pg_class') AS comment
+ FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace)
+ WHERE (n.nspname='{$this->_schema}') AND (c.relkind = 'v'::\"char\") ORDER BY viewname";
return $this->selectSet($sql);
}
* @return -2 drop view error
* @return -3 create view error
*/
- function setView($viewname, $definition) {
- return $this->createView($viewname, $definition, true);
+ function setView($viewname, $definition,$comment) {
+ return $this->createView($viewname, $definition, true, $comment);
}
// Sequence functions
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres74.php,v 1.24 2004/02/19 04:20:00 chriskl Exp $
+ * $Id: Postgres74.php,v 1.25 2004/03/12 08:56:54 chriskl Exp $
*/
include_once('./classes/database/Postgres73.php');
function &getSchemas() {
global $conf;
- if (!$conf['show_system']) $and = "AND nspname NOT LIKE 'pg\\\\_%' AND nspname != 'information_schema'";
+ if (!$conf['show_system']) $and = "WHERE nspname NOT LIKE 'pg\\\\_%' AND nspname != 'information_schema'";
else $and = '';
- $sql = "SELECT pn.nspname, pu.usename AS nspowner FROM pg_catalog.pg_namespace pn, pg_catalog.pg_user pu
- WHERE pn.nspowner = pu.usesysid
- {$and}ORDER BY nspname";
+ $sql = "SELECT pn.nspname, pu.usename AS nspowner, pg_catalog.obj_description(pn.oid, 'pg_namespace') AS comment
+ FROM pg_catalog.pg_namespace pn
+ JOIN pg_catalog.pg_user pu ON (pn.nspowner = pu.usesysid)
+ {$and} ORDER BY nspname";
return $this->selectSet($sql);
}
*/
function &getView($view) {
$this->clean($view);
-
- $sql = "SELECT relname AS viewname, pg_catalog.pg_get_userbyid(relowner) AS viewowner, pg_catalog.pg_get_viewdef(oid, true) AS definition\r
- FROM pg_class WHERE relkind='v' AND relname='{$view}'";\r
-
+ $sql = "SELECT c.relname AS viewname, pg_catalog.pg_get_userbyid(c.relowner) AS viewowner,
+ pg_catalog.pg_get_viewdef(c.oid) AS definition, pg_catalog.obj_description(c.oid, 'pg_class') AS comment
+ FROM pg_catalog.pg_class c
+ WHERE (c.relname = '$view')";
+
return $this->selectSet($sql);
}
/**
* Manage schemas within a database
*
- * $Id: database.php,v 1.36 2004/02/14 04:21:02 chriskl Exp $
+ * $Id: database.php,v 1.37 2004/03/12 08:56:51 chriskl Exp $
*/
// Include application functions
if (!isset($_POST['formName'])) $_POST['formName'] = '';
if (!isset($_POST['formAuth'])) $_POST['formAuth'] = $_SESSION['webdbUsername'];
+ if (!isset($_POST['formComment'])) $_POST['formComment'] = '';
// Fetch all users from the database
$users = &$data->getUsers();
($uname == $_POST['formAuth']) ? ' selected="selected"' : '', ">{$uname}</option>\n";
$users->moveNext();
}
- echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
+ echo "\t\t\t</select>\n\t\t</td>\n\t\n";
+
+ echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
+ echo "\t\t<td class=\"data1\"><input name=\"formComment\" size=\"60\" value=\"",
+ htmlspecialchars($_POST['formComment']), "\" /></td>\n\t</tr>\n";
+ echo "\t</tr>\n";
echo "</table>\n";
echo "<p>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
// Check that they've given a name
if ($_POST['formName'] == '') doCreate($lang['strschemaneedsname']);
else {
- $status = $data->createSchema($_POST['formName'], $_POST['formAuth']);
+ $status = $data->createSchema($_POST['formName'], $_POST['formAuth'],$_POST['formComment']);
if ($status == 0) {
$_reload_browser = true;
doDefault($lang['strschemacreated']);
if ($schemas->recordCount() > 0) {
echo "<table>\n";
echo "<tr><th class=\"data\">{$lang['strname']}</th><th class=\"data\">{$lang['strowner']}</th>";
- echo "<th colspan=\"2\" class=\"data\">{$lang['stractions']}</th>\n";
+ echo "<th colspan=\"3\" class=\"data\">{$lang['stractions']}</th><th class=\"data\">{$lang['strcomment']}</th>\n";
$i = 0;
while (!$schemas->EOF) {
$id = (($i % 2) == 0 ? '1' : '2');
echo "<td class=\"opbutton{$id}\"><a href=\"privileges.php?database=",
urlencode($_REQUEST['database']), "&object=",
urlencode($schemas->f[$data->nspFields['nspname']]), "&type=schema\">{$lang['strprivileges']}</a></td>\n";
+ echo "<td class=\"opbutton{$id}\"><a href=\"schema.php?database=",
+ urlencode($_REQUEST['database']), "&schema=",
+ urlencode($schemas->f[$data->nspFields['nspname']]), "&action=alter\">{$lang['stralter']}</a></td>\n";
+ echo "<td class=\"data{$id}\">", $misc->printVal($schemas->f[$data->nspFields['nspcomment']]), "</td>\n";
echo "</tr>\n";
$schemas->moveNext();
$i++;
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.134 2004/03/12 01:12:11 soranzo Exp $
+ * $Id: english.php,v 1.135 2004/03/12 08:56:54 chriskl Exp $
*/
// Language and character set
$lang['strconfdropschema'] = 'Are you sure you want to drop the schema "%s"?';
$lang['strschemadropped'] = 'Schema dropped.';
$lang['strschemadroppedbad'] = 'Schema drop failed.';
+ $lang['strschemaaltered'] = 'Schema altered';
+ $lang['strschemaalteredbad'] = 'Schema alter failed';
// Reports
$lang['strreport'] = 'Report';
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.87 2004/03/12 01:12:11 soranzo Exp $
+ * $Id: english.php,v 1.88 2004/03/12 08:56:55 chriskl Exp $
*/
// Language and character set
$lang['strconfdropschema'] = 'Are you sure you want to drop the schema "%s"?';
$lang['strschemadropped'] = 'Schema dropped.';
$lang['strschemadroppedbad'] = 'Schema drop failed.';
+ $lang['strschemaaltered'] = 'Schema altered';
+ $lang['strschemaalteredbad'] = 'Schema alter failed';
// Reports
$lang['strreport'] = 'Report';
/**
* Display properties of a schema
*
- * $Id: schema.php,v 1.13 2003/12/24 11:12:20 chriskl Exp $
+ * $Id: schema.php,v 1.14 2004/03/12 08:56:51 chriskl Exp $
*/
- // Include application functions (no db conn)
- $_no_db_connection = true;
include_once('./libraries/lib.inc.php');
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
* Show schema properties
*/
function doDefault($msg = '') {
- global $misc, $lang, $conf;
+ global $data, $misc, $lang, $conf;
+
+ $schema = &$data->getSchemaByName($_REQUEST['schema']);
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strschemas']}: ",
$misc->printVal($_REQUEST['schema']), "</h2>\n";
+
+ // Show comment if any
+ if ($schema->f[$data->nspFields['nspcomment']] != null)
+ echo "<p class=\"comment\">", htmlspecialchars($schema->f[$data->nspFields['nspcomment']]), "</p>\n";
+
+ $misc->printMsg($msg);
echo "<ul>\n";
echo "<li><a href=\"tables.php?{$misc->href}\">{$lang['strtables']}</a></li>\n";
echo "<li><a href=\"sequences.php?{$misc->href}\">{$lang['strsequences']}</a></li>\n";
echo "<li><a href=\"functions.php?{$misc->href}\">{$lang['strfunctions']}</a></li>\n";
echo "<li><a href=\"domains.php?{$misc->href}\">{$lang['strdomains']}</a></li>\n";
+ echo "<li><a href=\"schema.php?database=", urlencode($_REQUEST['database']), "&schema=",
+ urlencode($_REQUEST['schema']),"&action=alter\">{$lang['stralter']}</a></li>\n";
if ($conf['show_advanced']) {
echo "<li>{$lang['stradvanced']}</li>\n";
echo "<ul>\n";
echo "</ul>\n";
}
+ /**
+ * Display a form to permit editing schema properies.
+ * TODO: permit changing name, owner
+ */
+ function doAlter($msg = '') {
+ global $data, $misc,$PHP_SELF, $lang;
+
+ echo "<h2>", $misc->printVal($_REQUEST['database']), ": ", $misc->printVal($_REQUEST['schema']), ": {$lang['stralter']}</h2>\n";
+ $misc->printMsg($msg);
+
+ $schema = &$data->getSchemaByName($_REQUEST['schema']);
+ if ($schema->recordCount() > 0) {
+ if (!isset($_POST['comment'])) $_POST['comment'] = $schema->f[$data->nspFields['nspcomment']];
+ if (!isset($_POST['schema'])) $_POST['schema'] = $_REQUEST['schema'];
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<table>\n";
+ echo "\t<tr>\n";
+ echo "\t\t<th class=\"data\">{$lang['strcomment']}</th>\n";
+ echo "\t\t<td class=\"data1\"><input type=\"text\" size=\"60\" name =\"comment\" value=\"", htmlspecialchars($_POST['comment']), "\" /></td>\n";
+ echo "\t</tr>\n";
+ echo "</table>\n";
+ echo "<p><input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
+ echo "<input type=\"hidden\" name=\"schema\" value=\"", htmlspecialchars($_POST['schema']), "\" />\n";
+ echo $misc->form;
+ echo "<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";
+ }
+
+ }
+
+ /**
+ * Save the form submission containing changes to a schema
+ */
+ function doSaveAlter($msg = '') {
+ global $data, $misc,$PHP_SELF, $lang;
+
+
+ $status = $data->updateSchema($_POST['schema'], $_POST['comment']);
+ if ($status == 0)
+ doDefault($lang['strschemaaltered']);
+ else
+ doAlter($lang['strschemaalteredbad']);
+ }
+
+
$misc->printHeader($lang['strschema'] . ' - ' . $_REQUEST['schema']);
$misc->printBody();
switch ($action) {
+ case 'alter':
+ if (isset($_POST['cancel']))
+ doDefault();
+ elseif (isset($_POST['alter']))
+ doSaveAlter();
+ else
+ doAlter();
+ break;
default:
- doDefault();
- break;
+ doDefault();
}
+
$misc->printFooter();
/**
* List tables in a database
*
- * $Id: tables.php,v 1.44 2004/01/03 10:16:57 chriskl Exp $
+ * $Id: tables.php,v 1.45 2004/03/12 08:56:51 chriskl Exp $
*/
// Include application functions
if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1;
if (!isset($_REQUEST['name'])) $_REQUEST['name'] = '';
if (!isset($_REQUEST['fields'])) $_REQUEST['fields'] = '';
+ if (!isset($_REQUEST['tblcomment'])) $_REQUEST['tblcomment'] = '';
switch ($_REQUEST['stage']) {
case 1:
echo "<td class=\"data\"><input type=\"checkbox\" name=\"withoutoids\"",
(isset($_REQUEST['withoutoids']) ? ' checked="checked"' : ''), " />WITHOUT OIDS</td></tr>\n";
}
+
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n";
echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
// Output table header
echo "<table>\n";
- echo "<tr><th colspan=\"2\" class=\"data\">{$lang['strfield']}</th><th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['strlength']}</th><th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th></tr>\n";
+ echo "<tr><th class=\"data left\" colspan=\"2\">{$lang['strcomment']}</th><td colspan=\"5\"><input style=\"width: 100%;\" name=\"tblcomment\" value='",
+ htmlspecialchars($_REQUEST['tblcomment']), "' /></td></tr>\n";
+ echo "<tr><td colspan=\"7\"> </td></tr>\n";
+ echo "<tr><th colspan=\"2\" class=\"data\">{$lang['strfield']}</th><th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['strlength']}</th><th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>\n";
for ($i = 0; $i < $_REQUEST['fields']; $i++) {
if (!isset($_REQUEST['field'][$i])) $_REQUEST['field'][$i] = '';
if (!isset($_REQUEST['length'][$i])) $_REQUEST['length'][$i] = '';
if (!isset($_REQUEST['default'][$i])) $_REQUEST['default'][$i] = '';
+ if (!isset($_REQUEST['colcomment'][$i])) $_REQUEST['colcomment'][$i] = '';
+
echo "<tr><td>", $i + 1, ". </td>";
echo "<td><input name=\"field[{$i}]\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_REQUEST['field'][$i]), "\" /></td>";
htmlspecialchars($_REQUEST['length'][$i]), "\" /></td>";
echo "<td><input type=\"checkbox\" name=\"notnull[{$i}]\"", (isset($_REQUEST['notnull'][$i])) ? ' checked="checked"' : '', " /></td>";
echo "<td><input name=\"default[{$i}]\" size=\"20\" value=\"",
- htmlspecialchars($_REQUEST['default'][$i]), "\" /></td></tr>\n";
- }
-
+ htmlspecialchars($_REQUEST['default'][$i]), "\" /></td>";
+ echo "<td><input name=\"colcomment[{$i}]\" size=\"40\" value=\"",
+ htmlspecialchars($_REQUEST['colcomment'][$i]), "\" /></td></tr>\n";
+ }
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n";
echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n";
$status = $data->createTable($_REQUEST['name'], $_REQUEST['fields'], $_REQUEST['field'],
$_REQUEST['type'], $_REQUEST['length'], $_REQUEST['notnull'], $_REQUEST['default'],
- isset($_REQUEST['withoutoids']));
+ isset($_REQUEST['withoutoids']), $_REQUEST['colcomment'], $_REQUEST['tblcomment']);
if ($status == 0) {
$_reload_browser = true;
doDefault($lang['strtablecreated']);
/**
* List tables in a database
*
- * $Id: tblproperties.php,v 1.36 2004/02/05 06:45:57 chriskl Exp $
+ * $Id: tblproperties.php,v 1.37 2004/03/12 08:56:51 chriskl Exp $
*/
// Include application functions
if (!isset($_POST['field'])) $_POST['field'] = '';
if (!isset($_POST['type'])) $_POST['type'] = '';
if (!isset($_POST['length'])) $_POST['length'] = '';
+ if (!isset($_POST['comment'])) $_POST['comment'] = '';
// Fetch all available types
$types = &$data->getTypes(true);
// Output table header
echo "<table>\n<tr>";
- echo "<tr><th class=\"data required\">{$lang['strfield']}</th><th class=\"data required\">{$lang['strtype']}</th><th class=\"data\">{$lang['strlength']}</th></tr>";
+ echo "<tr><th class=\"data required\">{$lang['strfield']}</th><th class=\"data required\">{$lang['strtype']}</th><th class=\"data\">{$lang['strlength']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>";
echo "<tr><td><input name=\"field\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_POST['field']), "\" /></td>";
}
echo "</select></td>\n";
echo "<td><input name=\"length\" size=\"8\" value=\"",
- htmlspecialchars($_POST['length']), "\" /></td></tr>";
+ htmlspecialchars($_POST['length']), "\" /></td>";
+ echo "<td><input name=\"comment\" size=\"60\" value=\"",
+ htmlspecialchars($_POST['comment']), "\" /></td></tr>";
echo "</table>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"add_column\" />\n";
echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
}
$status = $data->addColumn($_POST['table'], $_POST['field'],
- $_POST['type'], $_POST['length']);
+ $_POST['type'], $_POST['length'],$_POST['comment']);
if ($status == 0)
doDefault($lang['strcolumnadded']);
else {
// Output table header
echo "<table>\n<tr>";
- echo "<tr><th class=\"data required\">{$lang['strname']}</th><th class=\"data required\">{$lang['strtype']}</th><th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th></tr>";
+ echo "<tr><th class=\"data required\">{$lang['strname']}</th><th class=\"data required\">{$lang['strtype']}</th><th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>";
$column = &$data->getTableAttributes($_REQUEST['table'], $_REQUEST['column']);
$column->f['attnotnull'] = $data->phpBool($column->f['attnotnull']);
$_REQUEST['field'] = $column->f['attname'];
$_REQUEST['default'] = $_REQUEST['olddefault'] = $column->f['adsrc'];
if ($column->f['attnotnull']) $_REQUEST['notnull'] = 'YES';
+ $_REQUEST['comment'] = $column->f['comment'];
}
echo "<tr><td><input name=\"field\" size=\"32\" value=\"",
echo "<td><input type=\"checkbox\" name=\"notnull\"", (isset($_REQUEST['notnull'])) ? ' checked="checked"' : '', " /></td>\n";
echo "<td><input name=\"default\" size=\"20\" value=\"",
htmlspecialchars($_REQUEST['default']), "\" /></td>";
+ echo "<td><input name=\"comment\" size=\"60\" value=\"",
+ htmlspecialchars($_REQUEST['comment']), "\" /></td>";
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"properties\" />\n";
}
$status = $data->alterColumn($_REQUEST['table'], $_REQUEST['column'], $_REQUEST['field'],
- isset($_REQUEST['notnull']), $_REQUEST['default'], $_REQUEST['olddefault']);
+ isset($_REQUEST['notnull']), $_REQUEST['default'], $_REQUEST['olddefault'],$_REQUEST['comment']);
if ($status == 0)
doDefault($lang['strcolumnaltered']);
else {
echo "\t<th colspan=\"2\" class=\"data\">{$lang['stractions']}</th>\n";
else
echo "\t<th class=\"data\">{$lang['stractions']}</th>\n";
- echo "</tr>\n";
+ echo "\t<th class=\"data\">{$lang['strcomment']}</th>\n";
+ echo "</tr>\n";
$i = 0;
while (!$attrs->EOF) {
echo "\t<td class=\"opbutton{$id}\"><a href=\"{$PHP_SELF}?{$misc->href}&table=", urlencode($_REQUEST['table']),
"&column=", urlencode($attrs->f['attname']), "&action=confirm_drop\">{$lang['strdrop']}</a></td>\n";
}
+ echo "\t<td class=\"data{$id}\">", $misc->printVal($attrs->f['comment']), "</td>\n";
echo "</tr>\n";
$attrs->moveNext();
$i++;
/**
* Manage views in a database
*
- * $Id: views.php,v 1.27 2003/12/21 02:03:15 chriskl Exp $
+ * $Id: views.php,v 1.28 2004/03/12 08:56:52 chriskl Exp $
*/
// Include application functions
function doSaveEdit() {
global $data, $lang;
- $status = $data->setView($_POST['view'], $_POST['formDefinition']);
+ $status = $data->setView($_POST['view'], $_POST['formDefinition'], $_POST['formComment']);
if ($status == 0)
doProperties($lang['strviewupdated']);
else
if ($viewdata->recordCount() > 0) {
- if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = $viewdata->f[$data->vwFields['vwdef']];
+ if (!isset($_POST['formDefinition'])) {
+ $_POST['formDefinition'] = $viewdata->f[$data->vwFields['vwdef']];
+ $_POST['formComment'] = $viewdata->f[$data->vwFields['vwcomment']];
+ }
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo "<table width=\"100%\">\n";
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strdefinition']}</th>\n";
echo "\t\t<td class=\"data1\"><textarea style=\"width: 100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\" wrap=\"virtual\">",
htmlspecialchars($_POST['formDefinition']), "</textarea></td>\n\t</tr>\n";
+ echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strcomment']}</th>\n";
+ echo "\t\t<td class=\"data1\"><input style=\"width: 100%;\" name=\"formComment\" value='",
+ htmlspecialchars($_POST['formComment']), "' /></td>\n\t</tr>\n";
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
echo "\t\t<td class=\"data1\">", $misc->printVal($viewdata->f[$data->vwFields['vwname']]), "</td>\n\t</tr>\n";
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strdefinition']}</th>\n";
echo "\t\t<td class=\"data1\">", $misc->printVal($viewdata->f[$data->vwFields['vwdef']]), "</td>\n\t</tr>\n";
+ echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
+ echo "\t\t<td class=\"data1\">", $misc->printVal($viewdata->f[$data->vwFields['vwcomment']]), "</td>\n\t</tr>\n";
echo "</table>\n";
}
else echo "<p>{$lang['strnodata']}</p>\n";
if (!isset($_REQUEST['formView'])) $_REQUEST['formView'] = '';
if (!isset($_REQUEST['formDefinition'])) $_REQUEST['formDefinition'] = 'SELECT ';
+ if (!isset($_REQUEST['formComment'])) $_REQUEST['formComment'] = '';
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateview']}</h2>\n";
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strdefinition']}</th>\n";
echo "\t<td class=\"data1\"><textarea style=\"width:100%;\" rows=\"10\" cols=\"50\" name=\"formDefinition\" wrap=\"virtual\">",
htmlspecialchars($_REQUEST['formDefinition']), "</textarea></td>\n\t</tr>\n";
+ echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
+ echo "\t\t<td class=\"data1\"><input style=\"width: 100%;\" name=\"formComment\" value='",
+ htmlspecialchars($_REQUEST['formComment']), "' /></td>\n\t</tr>\n";
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
echo $misc->form;
if ($_POST['formView'] == '') doCreate($lang['strviewneedsname']);
elseif ($_POST['formDefinition'] == '') doCreate($lang['strviewneedsdef']);
else {
- $status = $data->createView($_POST['formView'], $_POST['formDefinition'], false);
+ $status = $data->createView($_POST['formView'], $_POST['formDefinition'], false, $_POST['formComment']);
if ($status == 0)
doDefault($lang['strviewcreated']);
else
if ($views->recordCount() > 0) {
echo "<table>\n";
echo "<tr><th class=\"data\">{$lang['strview']}</th><th class=\"data\">{$lang['strowner']}</th>";
- echo "<th colspan=\"5\" class=\"data\">{$lang['stractions']}</th></tr>\n";
+ echo "<th colspan=\"5\" class=\"data\">{$lang['stractions']}</th>\n";
+ echo "<th class=\"data\">{$lang['strcomment']}</th></tr>\n";
$i = 0;
while (!$views->EOF) {
// @@@@@@@@@ FIX THIS!!!!!
echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strdrop']}</a></td>\n";
echo "<td class=\"opbutton{$id}\"><a href=\"privileges.php?{$misc->href}&object=", urlencode($views->f[$data->vwFields['vwname']]),
"&type=view\">{$lang['strprivileges']}</a></td>\n";
+ echo "<td class=\"data{$id}\">", $misc->printVal($views->f[$data->vwFields['vwcomment']]), "</td>\n";
echo "</tr>\n";
$views->moveNext();
$i++;