add create composite type. add help links on users and groups
authorchriskl <chriskl>
Tue, 3 Aug 2004 09:20:14 +0000 (09:20 +0000)
committerchriskl <chriskl>
Tue, 3 Aug 2004 09:20:14 +0000 (09:20 +0000)
BUGS
HISTORY
classes/database/Postgres.php
classes/database/Postgres71.php
classes/database/Postgres73.php
lang/english.php
lang/recoded/english.php
types.php

diff --git a/BUGS b/BUGS
index 13e1223e45b491f8872d6ca33cb37ff4acb241f8..cb0a8c095e7bf200436b34d45938f1f479ea910e 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -33,4 +33,4 @@ NEEDS TESTING
 * Allows tabs in textareas on IE: http://devilock.mine.nu/textarea_tab.html
 * add help links everywhere.  fix formatting of help links.
 * Deal with named parameters that have ',' in the type name
-
+* make sure composite types are found in the find feature
diff --git a/HISTORY b/HISTORY
index 71aea5c1cf019d05def7c9e685479940f7140931..67c7078833f3bdca474bbf2785bdc030d9388d07 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -19,6 +19,7 @@ Features
 * New fast navigation bar.  A breadcrumb style navigation bar for fast
   jumping between areas.
 * Much improved grant/revoke feature
+* Allow creating and viewing composite types
 
 Translations
 * Arabic from Zaki
index 2c4244db0cbc333301e859d4ff1a44e7408c0b60..8873df7aea6f38868d2f1f95c9f065169dc102b7 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.241 2004/07/19 03:01:53 chriskl Exp $
+ * $Id: Postgres.php,v 1.242 2004/08/03 09:20:15 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -139,6 +139,8 @@ class Postgres extends BaseDB {
                'drop_type' => 'sql-droptype.htm',
                'operators' => 'xoper.htm',
                'managing_databases' => 'managing-databases.htm',
+               'users' => 'security17760.htm',
+               'groups' => 'security17760.htm',                
                'create_database' => 'sql-createdatabase.htm',
                'drop_database' => 'sql-dropdatabase.htm',
                'constraints' => 'ddl-constraints.htm'
@@ -3912,6 +3914,8 @@ class Postgres extends BaseDB {
        function hasTablespaces() { return false; }
        function hasSignals() { return false; }
        function hasNamedParams() { return false; }
+       function hasUserAndDbVariables() { return false; }
+       function hasCompositeTypes() { return false; }
 
 }
 
index 480422859e14aa00b8b5cbefa87bd7d5d69342fe..dc2c106f5b585c3714768cb4e8195a0125ebf584 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres71.php,v 1.64 2004/07/10 08:51:01 chriskl Exp $
+ * $Id: Postgres71.php,v 1.65 2004/08/03 09:20:15 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -81,6 +81,8 @@ class Postgres71 extends Postgres {
                'drop_type' => 'sql-droptype.html',
                'operators' => 'xoper.html',
                'managing_databases' => 'managing-databases.html',
+               'users' => 'user-manag.html#DATABASE-USERS',
+               'groups' => 'groups.html',
                'create_database' => 'sql-createdatabase.html',
                'drop_database' => 'sql-dropdatabase.html',
                'constraints' => 'ddl-constraints.html'
index 9e5a6eaf6cc65043c7d0c04f66e5d71215f2fce0..7cb7d8876e1dbdfefa4478e258636eb27a57d3b1 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.133 2004/07/22 13:29:19 jollytoad Exp $
+ * $Id: Postgres73.php,v 1.134 2004/08/03 09:20:15 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -894,7 +894,101 @@ class Postgres73 extends Postgres72 {
 
                return $this->selectSet($sql);
        }
-       
+
+       /**
+        * Creates a new composite type in the database
+        * @param $name The name of the type
+        * @param $fields The number of fields
+        * @param $field An array of field names
+        * @param $type An array of field types
+        * @param $array An array of '' or '[]' for each type if it's an array or not
+        * @param $length An array of field lengths
+        * @param $colcomment An array of comments
+        * @param $typcomment Type comment
+        * @return 0 success
+        * @return -1 no fields supplied
+        */
+       function createCompositeType($name, $fields, $field, $type, $array, $length, $colcomment, $typcomment) {
+               $this->fieldClean($name);
+               $this->clean($typcomment);
+
+               $status = $this->beginTransaction();
+               if ($status != 0) return -1;
+
+               $found = false;
+               $first = true;
+               $comment_sql = ''; // Accumulate comments for the columns
+               $sql = "CREATE TYPE \"{$name}\" AS (";
+               for ($i = 0; $i < $fields; $i++) {
+                       $this->fieldClean($field[$i]);
+                       $this->clean($type[$i]);
+                       $this->clean($length[$i]);
+                       $this->clean($colcomment[$i]);
+
+                       // Skip blank columns - for user convenience
+                       if ($field[$i] == '' || $type[$i] == '') continue;
+                       // If not the first column, add a comma
+                       if (!$first) $sql .= ", ";
+                       else $first = false;
+                       
+                       switch ($type[$i]) {
+                               // Have to account for weird placing of length for with/without
+                               // time zone types
+                               case 'timestamp with time zone':
+                               case 'timestamp without time zone':
+                                       $qual = substr($type[$i], 9);
+                                       $sql .= "\"{$field[$i]}\" timestamp";
+                                       if ($length[$i] != '') $sql .= "({$length[$i]})";
+                                       $sql .= $qual;
+                                       break;
+                               case 'time with time zone':
+                               case 'time without time zone':
+                                       $qual = substr($type[$i], 4);
+                                       $sql .= "\"{$field[$i]}\" time";
+                                       if ($length[$i] != '') $sql .= "({$length[$i]})";
+                                       $sql .= $qual;
+                                       break;
+                               default:
+                                       $sql .= "\"{$field[$i]}\" {$type[$i]}";
+                                       if ($length[$i] != '') $sql .= "({$length[$i]})";
+                       }
+                       // Add array qualifier if necessary
+                       if ($array[$i] == '[]') $sql .= '[]';
+
+                       if ($colcomment[$i] != '') $comment_sql .= "COMMENT ON COLUMN \"{$name}\".\"{$field[$i]}\" IS '{$colcomment[$i]}';\n";
+
+                       $found = true;
+               }
+               
+               if (!$found) return -1;
+               
+               $sql .= ")";
+                               
+               $status = $this->execute($sql);
+               if ($status) {
+                       $this->rollbackTransaction();
+                       return -1;
+               }
+
+               if ($typcomment != '') {
+                       $status = $this->setComment('TYPE', $name, '', $typcomment, true);
+                       if ($status) {
+                               $this->rollbackTransaction();
+                               return -1;
+                       }
+               }
+
+               if ($comment_sql != '') {
+                       $status = $this->execute($comment_sql);
+                       if ($status) {
+                               $this->rollbackTransaction();
+                               return -1;
+                       }
+               }
+               return $this->endTransaction();
+               
+       }
+               
        // Rule functions
        
        /**
@@ -1693,7 +1787,8 @@ class Postgres73 extends Postgres72 {
        function hasFullExplain() { return true; }
        function hasForeignKeysInfo() { return true; }
        function hasViewColumnRename() { return true; }
-
+       function hasUserAndDbVariables() { return true; }
+       function hasCompositeTypes() { return true; }   
 }
 
 ?>
index 88b08696420bbfd27e70aa93d334ff0cd2ea797e..9ac09d952465b3115eb8d15dac20d85c8fb6efc6 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.158 2004/07/23 07:28:24 chriskl Exp $
+        * $Id: english.php,v 1.159 2004/08/03 09:20:16 chriskl Exp $
         */
 
        // Language and character set
        $lang['strnotype'] = 'No type found.';
        $lang['strnotypes'] = 'No types found.';
        $lang['strcreatetype'] = 'Create type';
+       $lang['strcreatecomptype'] = 'Create composite type';
+       $lang['strtypeneedsfield'] = 'You must specify at least one field.';
+       $lang['strtypeneedscols'] = 'Composite types require a valid number of columns.';       
        $lang['strtypename'] = 'Type name';
        $lang['strinputfn'] = 'Input function';
        $lang['stroutputfn'] = 'Output function';
index 3a825a4fe6a16825ca9fd6ecb7cd118fd15b04ba..0fed1bff8f586e19474692b349b135743f315c7c 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.110 2004/07/23 07:28:24 chriskl Exp $
+        * $Id: english.php,v 1.111 2004/08/03 09:20:16 chriskl Exp $
         */
 
        // Language and character set
        $lang['strnotype'] = 'No type found.';
        $lang['strnotypes'] = 'No types found.';
        $lang['strcreatetype'] = 'Create type';
+       $lang['strcreatecomptype'] = 'Create composite type';
+       $lang['strtypeneedsfield'] = 'You must specify at least one field.';
+       $lang['strtypeneedscols'] = 'Composite types require a valid number of columns.';       
        $lang['strtypename'] = 'Type name';
        $lang['strinputfn'] = 'Input function';
        $lang['stroutputfn'] = 'Output function';
index 6d6bca83b0e18f43050cc448b8bea871c7d13552..7224f1300581f87efe9ea1e08feec6d38d2a46cf 100644 (file)
--- a/types.php
+++ b/types.php
@@ -3,7 +3,7 @@
        /**
         * Manage types in a database
         *
-        * $Id: types.php,v 1.21 2004/07/22 13:39:11 jollytoad Exp $
+        * $Id: types.php,v 1.22 2004/08/03 09:20:14 chriskl Exp $
         */
 
        // Include application functions
@@ -50,7 +50,7 @@
                                        'comment' => array(
                                                'title' => $lang['strcomment'],
                                                'field' => 'comment',
-                                       ),
+                                       )
                                );
                                
                                $actions = array();
                }
                
        }
+
+       /**
+        * Displays a screen where they can enter a new composite type
+        */
+       function doCreateComposite($msg = '') {
+               global $data, $misc;
+               global $PHP_SELF, $lang;
+
+               if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1;
+               if (!isset($_REQUEST['name'])) $_REQUEST['name'] = '';
+               if (!isset($_REQUEST['fields'])) $_REQUEST['fields'] = '';
+               if (!isset($_REQUEST['typcomment'])) $_REQUEST['typcomment'] = '';
+
+               switch ($_REQUEST['stage']) {
+                       case 1:
+                               $misc->printTitle(array($misc->printVal($_REQUEST['database']), $lang['strtypes'], $lang['strcreatecomptype']), 'create_type');
+                               $misc->printMsg($msg);
+                               
+                               echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                               echo "<table>\n";
+                               echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
+                               echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
+                                       htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n";
+                               echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strnumfields']}</th>\n";
+                               echo "\t\t<td class=\"data\"><input name=\"fields\" size=\"5\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
+                                       htmlspecialchars($_REQUEST['fields']), "\" /></td>\n\t</tr>\n";
+
+                               echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
+                               echo "\t\t<td><textarea name=\"typcomment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">", 
+                                       htmlspecialchars($_REQUEST['typcomment']), "</textarea></td>\n\t</tr>\n";
+
+                               echo "</table>\n";
+                               echo "<p><input type=\"hidden\" name=\"action\" value=\"create_comp\" />\n";
+                               echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
+                               echo $misc->form;
+                               echo "<input type=\"submit\" value=\"{$lang['strnext']}\" />\n";
+                               echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
+                               echo "</form>\n";
+                               break;
+                       case 2:
+                               global $lang;
+
+                               // Check inputs
+                               $fields = trim($_REQUEST['fields']);
+                               if (trim($_REQUEST['name']) == '') {
+                                       $_REQUEST['stage'] = 1;
+                                       doCreateComposite($lang['strtypeneedsname']);
+                                       return;
+                               }
+                               elseif ($fields == '' || !is_numeric($fields) || $fields != (int)$fields || $fields < 1)  {
+                                       $_REQUEST['stage'] = 1;
+                                       doCreateComposite($lang['strtypeneedscols']);
+                                       return;
+                               }
+
+                               $types = &$data->getTypes(true, false, true);
+       
+                               $misc->printTitle(array($misc->printVal($_REQUEST['database']), $lang['strtypes'], $lang['strcreatecomptype']), 'create_type');
+                               $misc->printMsg($msg);
+
+                               echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+
+                               // Output table header
+                               echo "<table>\n";
+                               echo "\t<tr><th colspan=\"2\" class=\"data required\">{$lang['strfield']}</th><th colspan=\"2\" class=\"data required\">{$lang['strtype']}</th>";
+                               echo"<th class=\"data\">{$lang['strlength']}</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['colcomment'][$i])) $_REQUEST['colcomment'][$i] = '';
+
+                                       echo "\t<tr>\n\t\t<td>", $i + 1, ".&nbsp;</td>\n";
+                                       echo "\t\t<td><input name=\"field[{$i}]\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
+                                               htmlspecialchars($_REQUEST['field'][$i]), "\" /></td>\n";
+                                       echo "\t\t<td>\n\t\t\t<select name=\"type[{$i}]\">\n";
+                                       $types->moveFirst();
+                                       while (!$types->EOF) {
+                                               $typname = $types->f['typname'];
+                                               echo "\t\t\t\t<option value=\"", htmlspecialchars($typname), "\"",
+                                               (isset($_REQUEST['type'][$i]) && $typname == $_REQUEST['type'][$i]) ? ' selected="selected"' : '', ">",
+                                                       $misc->printVal($typname), "</option>\n";
+                                               $types->moveNext();
+                                       }
+                                       echo "\t\t\t</select>\n\t\t</td>\n";
+                                       
+                                       // Output array type selector
+                                       echo "\t\t<td>\n\t\t\t<select name=\"array[{$i}]\">\n";
+                                       echo "\t\t\t\t<option value=\"\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '') ? ' selected="selected"' : '', "></option>\n";
+                                       echo "\t\t\t\t<option value=\"[]\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
+                                       echo "\t\t\t</select>\n\t\t</td>\n";
+                                       
+                                       echo "\t\t<td><input name=\"length[{$i}]\" size=\"10\" value=\"", 
+                                               htmlspecialchars($_REQUEST['length'][$i]), "\" /></td>\n";
+                                       echo "\t\t<td><input name=\"colcomment[{$i}]\" size=\"40\" value=\"", 
+                                               htmlspecialchars($_REQUEST['colcomment'][$i]), "\" /></td>\n\t</tr>\n";
+                               }       
+                               echo "</table>\n";
+                               echo "<p><input type=\"hidden\" name=\"action\" value=\"create_comp\" />\n";
+                               echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n";
+                               echo $misc->form;
+                               echo "<input type=\"hidden\" name=\"name\" value=\"", htmlspecialchars($_REQUEST['name']), "\" />\n";
+                               echo "<input type=\"hidden\" name=\"fields\" value=\"", htmlspecialchars($_REQUEST['fields']), "\" />\n";
+                               echo "<input type=\"hidden\" name=\"typcomment\" value=\"", htmlspecialchars($_REQUEST['typcomment']), "\" />\n";
+                               echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
+                               echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
+                               echo "</form>\n";
+                                                               
+                               break;
+                       case 3:
+                               global $data, $lang;
+
+                               // Check inputs
+                               $fields = trim($_REQUEST['fields']);
+                               if (trim($_REQUEST['name']) == '') {
+                                       $_REQUEST['stage'] = 1;
+                                       doCreateComposite($lang['strtypeneedsname']);
+                                       return;
+                               }
+                               elseif ($fields == '' || !is_numeric($fields) || $fields != (int)$fields || $fields <= 0)  {
+                                       $_REQUEST['stage'] = 1;
+                                       doCreateComposite($lang['strtypeneedscols']);   
+                                       return;
+                               }
+                               
+                               $status = $data->createCompositeType($_REQUEST['name'], $_REQUEST['fields'], $_REQUEST['field'],
+                                                               $_REQUEST['type'], $_REQUEST['array'], $_REQUEST['length'], $_REQUEST['colcomment'], 
+                                                               $_REQUEST['typcomment']);
+
+                               if ($status == 0)
+                                       doDefault($lang['strtypecreated']);
+                               elseif ($status == -1) {
+                                       $_REQUEST['stage'] = 2;
+                                       doCreateComposite($lang['strtypeneedsfield']);
+                                       return;
+                               }
+                               else {
+                                       $_REQUEST['stage'] = 2;
+                                       doCreateComposite($lang['strtypecreatedbad']);
+                                       return;
+                               }
+                               break;
+                       default:
+                               global $lang;
+                               echo "<p>{$lang['strinvalidparam']}</p>\n";
+               }
+       }
        
        /**
         * Displays a screen where they can enter a new type
                
                $misc->printTable($types, $columns, $actions, $lang['strnotypes']);
 
-               echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&amp;{$misc->href}\">{$lang['strcreatetype']}</a></p>\n";
+               echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&amp;{$misc->href}\">{$lang['strcreatetype']}</a>";
+               if ($data->hasCompositeTypes())
+                       echo "\n| <a class=\"navlink\" href=\"$PHP_SELF?action=create_comp&amp;{$misc->href}\">{$lang['strcreatecomptype']}</a>";
+               echo "</p>\n";
 
        }
 
        $misc->printNav('schema','types');
 
        switch ($action) {
+               case 'create_comp':
+                       if (isset($_POST['cancel'])) doDefault();
+                       else doCreateComposite();
+                       break;
                case 'save_create':
                        if (isset($_POST['cancel'])) doDefault();
                        else doSaveCreate();