From 2b784da7530e6cfc5dc4b1d68674cb0ff2c5a1d5 Mon Sep 17 00:00:00 2001 From: chriskl Date: Wed, 13 Aug 2003 09:21:40 +0000 Subject: [PATCH] view and edit table comments --- BUGS | 2 +- HISTORY | 1 + classes/database/Postgres.php | 25 ++++++++++++++++++++----- classes/database/Postgres73.php | 15 ++++++++++++--- tables.php | 25 ++++++++++++------------- tblproperties.php | 20 ++++++++++++++++---- 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/BUGS b/BUGS index b8e38c89..e974d78a 100644 --- a/BUGS +++ b/BUGS @@ -3,8 +3,8 @@ * Backport findObject to pre-7.3 * Add db comments everywhere * Add owner everywhere -* Cancel/ buttons everywhere * pg_dump feature!!! * reports - unindexed fk's - slow indexes +* Get table comments for pre-7.3 diff --git a/HISTORY b/HISTORY index 358ee4c0..ddca9b64 100644 --- a/HISTORY +++ b/HISTORY @@ -26,6 +26,7 @@ Features: * Support better formatted view dumps in 7.4 * When browsing data, numeric types are aligned right * Ability to create unique and partial indexes +* View and edit table comments Bug Fixes: * Lots of NULL value in table dump fixes (XML format changed slightly) diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index cc4e19f9..8248acf8 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.138 2003/08/12 08:18:54 chriskl Exp $ + * $Id: Postgres.php,v 1.139 2003/08/13 09:21:43 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -14,7 +14,7 @@ include_once('classes/database/BaseDB.php'); class Postgres extends BaseDB { var $dbFields = array('dbname' => 'datname', 'dbcomment' => 'description', 'encoding' => 'encoding', 'owner' => 'owner'); - var $tbFields = array('tbname' => 'tablename', 'tbowner' => 'tableowner'); + var $tbFields = array('tbname' => 'tablename', 'tbowner' => 'tableowner', 'tbcomment' => 'tablecomment'); var $vwFields = array('vwname' => 'viewname', 'vwowner' => 'viewowner', 'vwdef' => 'definition'); var $uFields = array('uname' => 'usename', 'usuper' => 'usesuper', 'ucreatedb' => 'usecreatedb', 'uexpires' => 'valuntil'); var $grpFields = array('groname' => 'groname', 'grolist' => 'grolist'); @@ -498,7 +498,8 @@ class Postgres extends BaseDB { function &getTable($table) { $this->clean($table); - $sql = "SELECT tablename, tableowner FROM pg_tables WHERE tablename='{$table}'"; + // @@ Need to add proper comments here + $sql = "SELECT relname AS tablename, tableowner, NULL AS tablecomment FROM pg_tables WHERE tablename='{$table}'"; return $this->selectSet($sql); } @@ -684,16 +685,19 @@ class Postgres extends BaseDB { * Alters a table * @param $table The name of the table * @param $name The new name for the table - * @param $owner The new owner for the table + * @param $owner The new owner for the table + * @param $comment The comment on the table * @return 0 success * @return -1 transaction error * @return -2 owner error * @return -3 rename error + * @return -4 comment error */ - function alterTable($table, $name, $owner) { + function alterTable($table, $name, $owner, $comment) { $this->fieldClean($table); $this->fieldClean($name); $this->fieldClean($owner); + $this->clean($comment); $status = $this->beginTransaction(); if ($status != 0) { @@ -701,6 +705,17 @@ class Postgres extends BaseDB { return -1; } + // Comment + $sql = "COMMENT ON TABLE \"{$table}\" IS "; + if ($comment == '') $sql .= 'NULL'; + else $sql .= "'{$comment}'"; + + $status = $this->execute($sql); + if ($status != 0) { + $this->rollbackTransaction(); + return -4; + } + // Owner if ($this->hasAlterTableOwner() && $owner != '') { $sql = "ALTER TABLE \"{$table}\" OWNER TO \"{$owner}\""; diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index 00b1b28b..e26f5248 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.58 2003/08/12 01:33:56 chriskl Exp $ + * $Id: Postgres73.php,v 1.59 2003/08/13 09:21:43 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -275,8 +275,17 @@ class Postgres73 extends Postgres72 { function &getTable($table) { $this->clean($table); - $sql = "SELECT tablename, tableowner FROM pg_catalog.pg_tables - WHERE tablename='{$table}' AND schemaname='{$this->_schema}'"; + $sql = " + SELECT + c.relname AS tablename, + u.usename AS tableowner, + pg_catalog.obj_description(c.oid, 'pg_class') AS tablecomment + FROM pg_catalog.pg_class c + LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner + LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace + WHERE c.relkind = 'r' + AND n.nspname = '{$this->_schema}' + AND c.relname = '{$table}'"; return $this->selectSet($sql); } diff --git a/tables.php b/tables.php index 6c960484..8ced37bd 100644 --- a/tables.php +++ b/tables.php @@ -3,7 +3,7 @@ /** * List tables in a database * - * $Id: tables.php,v 1.30 2003/08/07 06:19:25 chriskl Exp $ + * $Id: tables.php,v 1.31 2003/08/13 09:21:41 chriskl Exp $ */ // Include application functions @@ -662,29 +662,28 @@ global $data, $misc, $localData; global $PHP_SELF, $lang; - echo "

", $misc->printVal($_REQUEST['database']), "

\n"; + echo "

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

\n"; $tables = &$localData->getTables(); if ($tables->recordCount() > 0) { echo "\n"; - echo "\n"; + echo ""; + echo "\n"; $i = 0; while (!$tables->EOF) { $id = (($i % 2) == 0 ? '1' : '2'); - echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; echo "\n"; $tables->moveNext(); @@ -696,7 +695,7 @@ echo "

{$lang['strnotables']}

\n"; } - echo "

href}\">{$lang['strcreatetable']}

\n"; + echo "

href}\">{$lang['strcreatetable']}

\n"; } $misc->printHeader($lang['strtables']); diff --git a/tblproperties.php b/tblproperties.php index 5844b25c..53836c71 100644 --- a/tblproperties.php +++ b/tblproperties.php @@ -3,7 +3,7 @@ /** * List tables in a database * - * $Id: tblproperties.php,v 1.19 2003/08/07 06:19:25 chriskl Exp $ + * $Id: tblproperties.php,v 1.20 2003/08/13 09:21:42 chriskl Exp $ */ // Include application functions @@ -21,7 +21,7 @@ // For databases that don't allow owner change if (!isset($_POST['owner'])) $_POST['owner'] = ''; - $status = $localData->alterTable($_POST['table'], $_POST['name'], $_POST['owner']); + $status = $localData->alterTable($_POST['table'], $_POST['name'], $_POST['owner'], $_POST['comment']); if ($status == 0) { // Jump them to the new table name $_REQUEST['table'] = $_POST['name']; @@ -52,13 +52,14 @@ if (!isset($_POST['name'])) $_POST['name'] = $table->f[$data->tbFields['tbname']]; if (!isset($_POST['owner'])) $_POST['owner'] = $table->f[$data->tbFields['tbowner']]; + if (!isset($_POST['comment'])) $_POST['comment'] = $table->f[$data->tbFields['tbcomment']]; echo "\n"; echo "
{$lang['strtable']}{$lang['strowner']}{$lang['stractions']}
{$lang['strtable']}{$lang['strowner']}{$lang['stractions']}
", $misc->printVal($tables->f[$data->tbFields['tbname']]), "", $misc->printVal($tables->f[$data->tbFields['tbowner']]), "href}&table=", + echo "
", $misc->printVal($tables->f[$data->tbFields['tbname']]), "", $misc->printVal($tables->f[$data->tbFields['tbowner']]), "href}&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strbrowse']}href}&table=", + echo "href}&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strselect']}href}&table=", + echo "href}&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strinsert']}href}&table=", + echo "href}&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strproperties']}href}&table=", - urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strempty']}href}&table=", + echo "href}&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strdrop']}
\n"; echo "\n"; echo "\n"; if ($data->hasAlterTableOwner()) { echo "\n"; echo "\n"; } + echo "\n"; + echo "\n"; echo "
{$lang['strname']}"; echo "_maxNameLen}\" value=\"", - htmlspecialchars($_POST['name']), "\" />\n"; + htmlspecialchars($_POST['name']), "\" />
{$lang['strowner']}
{$lang['strcomment']}"; + echo "
\n"; echo "

\n"; echo "\n"; @@ -311,9 +316,16 @@ $misc->printTableNav(); echo "

", $misc->printVal($_REQUEST['database']), ": ", $misc->printVal($_REQUEST['table']), "

\n"; - $attrs = &$localData->getTableAttributes($_REQUEST['table']); + // Get table + $tdata = &$localData->getTable($_REQUEST['table']); + // Get columns + $attrs = &$localData->getTableAttributes($_REQUEST['table']); $misc->printMsg($msg); + // Show comment if any + if ($tdata->f[$data->tbFields['tbcomment']] != null) + echo "

", htmlspecialchars($tdata->f[$data->tbFields['tbcomment']]), "

\n"; + echo "\n"; echo ""; echo ""; -- 2.39.5
{$lang['strfield']}{$lang['strtype']}{$lang['strnotnull']}{$lang['strdefault']}