commit Dan Boren's first phppgadmin patch. there ar e a few small things he still...
authorchriskl <chriskl>
Fri, 12 Mar 2004 08:56:50 +0000 (08:56 +0000)
committerchriskl <chriskl>
Fri, 12 Mar 2004 08:56:50 +0000 (08:56 +0000)
14 files changed:
BUGS
CREDITS
HISTORY
classes/database/Postgres.php
classes/database/Postgres72.php
classes/database/Postgres73.php
classes/database/Postgres74.php
database.php
lang/english.php
lang/recoded/english.php
schema.php
tables.php
tblproperties.php
views.php

diff --git a/BUGS b/BUGS
index b7597a01d57830a07d93c0cbe35f3311932454c4..bd69d5465294ae716d6dbee4dc76f874196b13e5 100644 (file)
--- 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 ed4dcdf837c407c29167dc89e0400989051e78ea..9297a07beb4bcdf069a831cd5369b1593dba228d 100644 (file)
--- 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 12d634cd5597f062e62cf8131b5d830be98748a0..3aff332c7035f9031de07833b1729bacecefc3b1 100644 (file)
--- 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
index 695d5452162e885f766f040849580e5658844dd1..46e9e20134c0b871ebb653690a8dd2919f1ce0b5 100755 (executable)
@@ -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;
index 484c05cbbc1f3015e175a120f5494894597d0822..5d87424c6c418bc07b25f0e0879f811c9fa716a7 100644 (file)
@@ -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}'
index 935ecb3d9cbded2487b05d7c733f46349d496139..f958b5bc40697b2d910c811779a9b40efdcee69c 100644 (file)
@@ -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
index 4b7974ed7ea0b3272f994b02ab899117bd7c1b57..3a3bddf1d9b0bb2b30c2c56132547cbfdd37c0e8 100644 (file)
@@ -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\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);
        }       
 
index a1c755f8429f6a83465db2accdd59a1763ad28a1..4e40f5fb4e4c9f71ed1c39d732fa1d86390f33f1 100755 (executable)
@@ -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
 
                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']), "&amp;object=",
                                                urlencode($schemas->f[$data->nspFields['nspname']]), "&amp;type=schema\">{$lang['strprivileges']}</a></td>\n";
+                                       echo "<td class=\"opbutton{$id}\"><a href=\"schema.php?database=",
+                                               urlencode($_REQUEST['database']), "&amp;schema=",
+                                               urlencode($schemas->f[$data->nspFields['nspname']]), "&amp;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++;
index 55cf2a42dd12c30f281154b1c14a0141c6cd54d4..139ab7f6f486e4ec618f6525bd7196137e3e2bb4 100755 (executable)
@@ -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
        $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';
index ffdf3766761a47411ffb7c416f1d0fa109375143..8d9067d6d6b6ea48192ab3824ea86a410cf7f02c 100644 (file)
@@ -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
        $lang['strconfdropschema'] = 'Are you sure you want to drop the schema &quot;%s&quot;?';
        $lang['strschemadropped'] = 'Schema dropped.';
        $lang['strschemadroppedbad'] = 'Schema drop failed.';
+       $lang['strschemaaltered'] = 'Schema altered';
+       $lang['strschemaalteredbad'] = 'Schema alter failed';
 
        // Reports
        $lang['strreport'] = 'Report';
index 81616dcb6232ef28622892c9bf0b79d738a05db4..44b8324460df661f0eb5673af62cdb1a661999ca 100755 (executable)
@@ -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'] : '';
         * 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";
@@ -29,6 +35,8 @@
                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']), "&amp;schema=",
+                       urlencode($_REQUEST['schema']),"&amp;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();
 
index abdb8f7fffb5b1fd5bb42678d94a2629bd7b52b6..baa131cd945c344df978d438d4698967a2a94df3 100644 (file)
@@ -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 "<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\">&nbsp;</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, ".&nbsp;</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']);
index 89d4a2b8e9e14420148c6f242ca024f6fe3e19dc..38d8583f76d695996880412d302e74e5d7c2a5e2 100644 (file)
@@ -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
                                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++;
index f742f3d8e8d967f6f247d2f6d45c7584bc1bf262..66fff5bdec111f967faba59c90a8452b36334495 100644 (file)
--- 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
        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++;