From 74072a7a624da70fd3b96009c8194d04ef0ca871 Mon Sep 17 00:00:00 2001 From: chriskl Date: Fri, 12 Mar 2004 08:56:50 +0000 Subject: [PATCH] commit Dan Boren's first phppgadmin patch. there ar e a few small things he still needs to fix, but he's been told about them. this patch adds viewing, editing and dropping comments on views, schemas and columns --- BUGS | 2 + CREDITS | 1 + HISTORY | 4 + classes/database/Postgres.php | 191 +++++++++++++++++++++++++++----- classes/database/Postgres72.php | 10 +- classes/database/Postgres73.php | 67 ++++++++--- classes/database/Postgres74.php | 20 ++-- database.php | 18 ++- lang/english.php | 4 +- lang/recoded/english.php | 4 +- schema.php | 77 ++++++++++++- tables.php | 20 +++- tblproperties.php | 22 ++-- views.php | 24 +++- 14 files changed, 379 insertions(+), 85 deletions(-) diff --git a/BUGS b/BUGS index b7597a01..bd69d546 100644 --- a/BUGS +++ b/BUGS @@ -20,3 +20,5 @@ Need to fix: * 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 + diff --git a/CREDITS b/CREDITS index ed4dcdf8..9297a07b 100644 --- a/CREDITS +++ b/CREDITS @@ -43,4 +43,5 @@ Contributors - Nicola Soranzo - Oliver Meyer & Sven Kiera (Table icons link to browse table) - Bryan Encina (SQL window improvements, bug fixes) +- Dan Boren (Object comments) diff --git a/HISTORY b/HISTORY index 12d634cd..3aff332c 100644 --- a/HISTORY +++ b/HISTORY @@ -6,6 +6,10 @@ Version 3.4-dev 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 diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index 695d5452..46e9e201 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -4,7 +4,7 @@ * 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??? @@ -15,7 +15,7 @@ class Postgres extends BaseDB { 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' ); @@ -359,6 +359,7 @@ class Postgres extends BaseDB { $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) { @@ -387,6 +388,12 @@ class Postgres extends BaseDB { 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++; } @@ -502,11 +509,14 @@ class Postgres extends BaseDB { // 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)) { @@ -950,10 +960,11 @@ class Postgres extends BaseDB { $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); } @@ -1066,13 +1077,15 @@ class Postgres extends BaseDB { * @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 @@ -1104,6 +1117,12 @@ class Postgres extends BaseDB { } } + $status = $this->setComment('COLUMN', $column, $table, $comment); + if ($status != 0) { + $this->rollbackTransaction(); + return -4; + } + return $this->endTransaction(); } @@ -1117,18 +1136,25 @@ class Postgres extends BaseDB { * @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; @@ -1159,6 +1185,8 @@ class Postgres extends BaseDB { 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; } @@ -1170,7 +1198,29 @@ class Postgres extends BaseDB { 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(); + } /** @@ -1199,11 +1249,7 @@ class Postgres extends BaseDB { } // 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; @@ -1719,11 +1765,12 @@ class Postgres extends BaseDB { * @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}"; @@ -1745,7 +1792,23 @@ class Postgres extends BaseDB { $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(); } /** @@ -1848,6 +1911,47 @@ class Postgres extends BaseDB { 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 @@ -1999,11 +2103,17 @@ class Postgres extends BaseDB { */ 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); } @@ -2016,8 +2126,11 @@ class Postgres extends BaseDB { 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); } @@ -2028,15 +2141,34 @@ class Postgres extends BaseDB { * @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(); } /** @@ -2063,8 +2195,9 @@ class Postgres extends BaseDB { * @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; @@ -2074,7 +2207,7 @@ class Postgres extends BaseDB { return -2; } - $status = $this->createView($viewname, $definition, false); + $status = $this->createView($viewname, $definition, false, $comment); if ($status != 0) { $this->rollbackTransaction(); return -3; diff --git a/classes/database/Postgres72.php b/classes/database/Postgres72.php index 484c05cb..5d87424c 100644 --- a/classes/database/Postgres72.php +++ b/classes/database/Postgres72.php @@ -4,7 +4,7 @@ * 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 $ */ @@ -101,11 +101,13 @@ class Postgres72 extends Postgres71 { 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 @@ -117,11 +119,13 @@ class Postgres72 extends Postgres71 { 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}' diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index 935ecb3d..f958b5bc 100644 --- a/classes/database/Postgres73.php +++ b/classes/database/Postgres73.php @@ -4,7 +4,7 @@ * 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??? @@ -15,7 +15,7 @@ class Postgres73 extends Postgres72 { 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 @@ -100,9 +100,10 @@ class Postgres73 extends Postgres72 { 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); } @@ -114,8 +115,10 @@ class Postgres73 extends Postgres72 { */ 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); } /** @@ -125,14 +128,34 @@ class Postgres73 extends Postgres72 { * @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(); } /** @@ -150,6 +173,18 @@ class Postgres73 extends Postgres72 { 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 @@ -351,7 +386,8 @@ class Postgres73 extends Postgres72 { 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 @@ -371,7 +407,8 @@ class Postgres73 extends Postgres72 { 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 @@ -479,8 +516,10 @@ class Postgres73 extends Postgres72 { * @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); } @@ -494,8 +533,8 @@ class Postgres73 extends Postgres72 { * @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 diff --git a/classes/database/Postgres74.php b/classes/database/Postgres74.php index 4b7974ed..3a3bddf1 100644 --- a/classes/database/Postgres74.php +++ b/classes/database/Postgres74.php @@ -4,7 +4,7 @@ * 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'); @@ -118,11 +118,12 @@ class Postgres74 extends Postgres73 { 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); } @@ -162,10 +163,11 @@ class Postgres74 extends Postgres73 { */ 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 - FROM pg_class WHERE relkind='v' AND relname='{$view}'"; - + $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); } diff --git a/database.php b/database.php index a1c755f8..4e40f5fb 100755 --- a/database.php +++ b/database.php @@ -3,7 +3,7 @@ /** * 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 @@ -437,6 +437,7 @@ 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(); @@ -457,7 +458,12 @@ ($uname == $_POST['formAuth']) ? ' selected="selected"' : '', ">{$uname}\n"; $users->moveNext(); } - echo "\t\t\t\n\t\t\n\t\n"; + echo "\t\t\t\n\t\t\n\t\n"; + + echo "\t\n\t\t{$lang['strcomment']}\n"; + echo "\t\t\n\t\n"; + echo "\t\n"; echo "\n"; echo "

\n"; echo "\n"; @@ -477,7 +483,7 @@ // 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']); @@ -505,7 +511,7 @@ if ($schemas->recordCount() > 0) { echo "\n"; echo ""; - echo "\n"; + echo "\n"; $i = 0; while (!$schemas->EOF) { $id = (($i % 2) == 0 ? '1' : '2'); @@ -517,6 +523,10 @@ echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; $schemas->moveNext(); $i++; diff --git a/lang/english.php b/lang/english.php index 55cf2a42..139ab7f6 100755 --- a/lang/english.php +++ b/lang/english.php @@ -4,7 +4,7 @@ * 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 @@ -464,6 +464,8 @@ $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'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index ffdf3766..8d9067d6 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -4,7 +4,7 @@ * 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 @@ -464,6 +464,8 @@ $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'; diff --git a/schema.php b/schema.php index 81616dcb..44b83244 100755 --- a/schema.php +++ b/schema.php @@ -3,11 +3,9 @@ /** * 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'] : ''; @@ -18,10 +16,18 @@ * Show schema properties */ function doDefault($msg = '') { - global $misc, $lang, $conf; + global $data, $misc, $lang, $conf; + + $schema = &$data->getSchemaByName($_REQUEST['schema']); echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['strschemas']}: ", $misc->printVal($_REQUEST['schema']), "

\n"; + + // Show comment if any + if ($schema->f[$data->nspFields['nspcomment']] != null) + echo "

", htmlspecialchars($schema->f[$data->nspFields['nspcomment']]), "

\n"; + + $misc->printMsg($msg); echo "
{$lang['strname']}{$lang['strowner']}{$lang['stractions']}{$lang['stractions']}{$lang['strcomment']}{$lang['strprivileges']}{$lang['stralter']}", $misc->printVal($schemas->f[$data->nspFields['nspcomment']]), "
\n"; + echo "\t\n"; + echo "\t\t\n"; + echo "\t\t\n"; + echo "\t\n"; + echo "
{$lang['strcomment']}
\n"; + echo "

\n"; + echo "\n"; + echo $misc->form; + echo "\n"; + echo "

\n"; + echo "\n"; + } else { + echo "

{$lang['strnodata']}

\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(); diff --git a/tables.php b/tables.php index abdb8f7f..baa131cd 100644 --- a/tables.php +++ b/tables.php @@ -3,7 +3,7 @@ /** * 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 @@ -22,6 +22,7 @@ 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: @@ -41,6 +42,7 @@ echo "WITHOUT OIDS\n"; } + echo "\n"; echo "

\n"; echo "\n"; @@ -74,12 +76,17 @@ // Output table header echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; + echo "\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 ""; echo ""; @@ -103,9 +110,10 @@ htmlspecialchars($_REQUEST['length'][$i]), "\" />"; echo ""; echo "\n"; - } - + htmlspecialchars($_REQUEST['default'][$i]), "\" />"; + echo "\n"; + } echo "
{$lang['strfield']}{$lang['strtype']}{$lang['strlength']}{$lang['strnotnull']}{$lang['strdefault']}
{$lang['strcomment']}
 
{$lang['strfield']}{$lang['strtype']}{$lang['strlength']}{$lang['strnotnull']}{$lang['strdefault']}{$lang['strcomment']}
", $i + 1, ". _maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['field'][$i]), "\" />
\n"; echo "

\n"; echo "\n"; @@ -140,7 +148,7 @@ $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']); diff --git a/tblproperties.php b/tblproperties.php index 89d4a2b8..38d8583f 100644 --- a/tblproperties.php +++ b/tblproperties.php @@ -3,7 +3,7 @@ /** * 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 @@ -164,6 +164,7 @@ 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); @@ -176,7 +177,7 @@ // Output table header echo "\n"; - echo ""; + echo ""; echo ""; @@ -189,7 +190,9 @@ } echo "\n"; echo ""; + htmlspecialchars($_POST['length']), "\" />"; + echo ""; echo "
{$lang['strfield']}{$lang['strtype']}{$lang['strlength']}
{$lang['strfield']}{$lang['strtype']}{$lang['strlength']}{$lang['strcomment']}
_maxNameLen}\" value=\"", htmlspecialchars($_POST['field']), "\" />
\n"; echo "\n"; echo "\n"; @@ -211,7 +214,7 @@ } $status = $data->addColumn($_POST['table'], $_POST['field'], - $_POST['type'], $_POST['length']); + $_POST['type'], $_POST['length'],$_POST['comment']); if ($status == 0) doDefault($lang['strcolumnadded']); else { @@ -246,7 +249,7 @@ // Output table header echo "\n"; - echo ""; + echo ""; $column = &$data->getTableAttributes($_REQUEST['table'], $_REQUEST['column']); $column->f['attnotnull'] = $data->phpBool($column->f['attnotnull']); @@ -255,6 +258,7 @@ $_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 "\n"; echo ""; + echo ""; echo "
{$lang['strname']}{$lang['strtype']}{$lang['strnotnull']}{$lang['strdefault']}
{$lang['strname']}{$lang['strtype']}{$lang['strnotnull']}{$lang['strdefault']}{$lang['strcomment']}
\n"; echo "

\n"; @@ -287,7 +293,7 @@ } $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 { @@ -366,7 +372,8 @@ echo "\t{$lang['stractions']}\n"; else echo "\t{$lang['stractions']}\n"; - echo "\n"; + echo "\t{$lang['strcomment']}\n"; + echo "\n"; $i = 0; while (!$attrs->EOF) { @@ -382,6 +389,7 @@ echo "\thref}&table=", urlencode($_REQUEST['table']), "&column=", urlencode($attrs->f['attname']), "&action=confirm_drop\">{$lang['strdrop']}\n"; } + echo "\t", $misc->printVal($attrs->f['comment']), "\n"; echo "\n"; $attrs->moveNext(); $i++; diff --git a/views.php b/views.php index f742f3d8..66fff5bd 100644 --- a/views.php +++ b/views.php @@ -3,7 +3,7 @@ /** * 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 @@ -126,7 +126,7 @@ 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 @@ -147,13 +147,19 @@ 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 "

\n"; echo "\n"; echo "\t\n\t\t\n"; echo "\t\t\n\t\n"; + echo "\t\n\t\t\n"; + echo "\t\t\n\t\n"; echo "
{$lang['strdefinition']}
{$lang['strcomment']}
\n"; echo "

\n"; echo "\n"; @@ -183,6 +189,8 @@ echo "\t\t", $misc->printVal($viewdata->f[$data->vwFields['vwname']]), "\n\t\n"; echo "\t\n\t\t{$lang['strdefinition']}\n"; echo "\t\t", $misc->printVal($viewdata->f[$data->vwFields['vwdef']]), "\n\t\n"; + echo "\t\n\t\t{$lang['strcomment']}\n"; + echo "\t\t", $misc->printVal($viewdata->f[$data->vwFields['vwcomment']]), "\n\t\n"; echo "\n"; } else echo "

{$lang['strnodata']}

\n"; @@ -234,6 +242,7 @@ if (!isset($_REQUEST['formView'])) $_REQUEST['formView'] = ''; if (!isset($_REQUEST['formDefinition'])) $_REQUEST['formDefinition'] = 'SELECT '; + if (!isset($_REQUEST['formComment'])) $_REQUEST['formComment'] = ''; echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateview']}

\n"; @@ -248,6 +257,9 @@ echo "\t\n\t\t{$lang['strdefinition']}\n"; echo "\t\n\t\n"; + echo "\t\n\t\t{$lang['strcomment']}\n"; + echo "\t\t\n\t\n"; echo "\n"; echo "

\n"; echo $misc->form; @@ -266,7 +278,7 @@ 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 @@ -290,7 +302,8 @@ if ($views->recordCount() > 0) { echo "\n"; echo ""; - echo "\n"; + echo "\n"; + echo "\n"; $i = 0; while (!$views->EOF) { // @@@@@@@@@ FIX THIS!!!!! @@ -312,6 +325,7 @@ echo "\n"; echo "\n"; + echo "\n"; echo "\n"; $views->moveNext(); $i++; -- 2.39.5
{$lang['strview']}{$lang['strowner']}{$lang['stractions']}
{$lang['stractions']}{$lang['strcomment']}
href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strdrop']}href}&object=", urlencode($views->f[$data->vwFields['vwname']]), "&type=view\">{$lang['strprivileges']}", $misc->printVal($views->f[$data->vwFields['vwcomment']]), "