Removed 'Clustered?' column and 'Cluster'/'Reindex' actions from the constraints...
authorjollytoad <jollytoad>
Tue, 13 Jul 2004 16:33:36 +0000 (16:33 +0000)
committerjollytoad <jollytoad>
Tue, 13 Jul 2004 16:33:36 +0000 (16:33 +0000)
'Indexes' page now lists ALL indices, including primary/unique keys, and has an extra 'Constraints' column to indicate that the index backs a constraint.
Fixed some bugs.

classes/database/Postgres.php
classes/database/Postgres73.php
classes/database/Postgres74.php
constraints.php
indexes.php

index 556472db32278b7689adf11f09bef0c31f77f9e8..b64eeebcbe69a9558f3cb4a07a0012439e027792 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.234 2004/07/13 09:00:40 chriskl Exp $
+ * $Id: Postgres.php,v 1.235 2004/07/13 16:33:37 jollytoad Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -2093,7 +2093,6 @@ class Postgres extends BaseDB {
                $sql = "SELECT c2.relname AS indname, i.indisprimary, i.indisunique, pg_get_indexdef(i.indexrelid) AS inddef
                        FROM pg_class c, pg_class c2, pg_index i
                        WHERE c.relname = '{$table}' AND c.oid = i.indrelid AND i.indexrelid = c2.oid
-                       AND NOT i.indisprimary AND NOT i.indisunique
                        ORDER BY c2.relname";
 
                return $this->selectSet($sql);
index f48317423bb481398eb7a0a80bd35ece684edb34..60274f21332f4d6a934ba6ca8365474ddbd5a93e 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.126 2004/07/12 07:13:33 chriskl Exp $
+ * $Id: Postgres73.php,v 1.127 2004/07/13 16:33:36 jollytoad Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -345,7 +345,7 @@ class Postgres73 extends Postgres72 {
        function &getTables($all = false) {
                if ($all) {
                        // Exclude pg_catalog and information_schema tables
-                       $sql = "SELECT schemaname AS nspname, tablename AS relname, tableowner AS relname
+                       $sql = "SELECT schemaname AS nspname, tablename AS relname, tableowner AS relowner
                                 FROM pg_catalog.pg_tables 
                                WHERE schemaname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')
                                ORDER BY schemaname, tablename";
@@ -597,17 +597,11 @@ class Postgres73 extends Postgres72 {
        function &getIndexes($table = '') {
                $this->clean($table);
                
-               /* This select excludes any indexes that are just base indexes for constraints. */
                $sql = "SELECT c2.relname AS indname, i.indisprimary, i.indisunique, i.indisclustered,
                        pg_catalog.pg_get_indexdef(i.indexrelid) AS inddef
                        FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
                        WHERE c.relname = '{$table}' AND pg_catalog.pg_table_is_visible(c.oid) 
                        AND c.oid = i.indrelid AND i.indexrelid = c2.oid
-                       AND NOT EXISTS (
-                               SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c
-                               ON (d.refclassid = c.tableoid AND d.refobjid = c.oid)
-                               WHERE d.classid = c2.tableoid AND d.objid = c2.oid AND d.deptype = 'i' AND c.contype IN ('u', 'p')
-                       )
                        ORDER BY c2.relname";
 
                return $this->selectSet($sql);
index 8e10f39608f285984426c7d0c9ae55d2da98a6c5..56c5c11cec3448735960fd0928808dbbd09de95a 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.35 2004/07/07 03:00:07 chriskl Exp $
+ * $Id: Postgres74.php,v 1.36 2004/07/13 16:33:37 jollytoad Exp $
  */
 
 include_once('./classes/database/Postgres73.php');
@@ -141,17 +141,11 @@ class Postgres74 extends Postgres73 {
        function &getIndexes($table = '') {
                $this->clean($table);
 
-               /* This select excludes any indexes that are just base indexes for constraints. */
                $sql = "SELECT c2.relname AS indname, i.indisprimary, i.indisunique, i.indisclustered,
                        pg_catalog.pg_get_indexdef(i.indexrelid, 0, true) AS inddef
                        FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
                        WHERE c.relname = '{$table}' AND pg_catalog.pg_table_is_visible(c.oid) 
                        AND c.oid = i.indrelid AND i.indexrelid = c2.oid
-                       AND NOT EXISTS (
-                               SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c
-                               ON (d.refclassid = c.tableoid AND d.refobjid = c.oid)
-                               WHERE d.classid = c2.tableoid AND d.objid = c2.oid AND d.deptype = 'i' AND c.contype IN ('u', 'p')
-                       )
                        ORDER BY c2.relname";
 
                return $this->selectSet($sql);
index 573b19e6348e507d7368117bc17b3ef29c64ba49..41f855af49be14f190005d3481b937225f551a70 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List constraints on a table
         *
-        * $Id: constraints.php,v 1.34 2004/07/13 16:13:15 jollytoad Exp $
+        * $Id: constraints.php,v 1.35 2004/07/13 16:33:37 jollytoad Exp $
         */
 
        // Include application functions
        $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
        $PHP_SELF = $_SERVER['PHP_SELF'];
 
-       /**
-        * Show confirmation of cluster index and perform actual cluster
-        */
-       function doClusterIndex($confirm) {
-               global $data, $misc, $action;
-               global $PHP_SELF, $lang;
-
-               if ($confirm) {
-                       // Default analyze to on
-                       $_REQUEST['analyze'] = true;
-                       
-                       echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
-                               $misc->printVal($_REQUEST['table']), ": " , $misc->printVal($_REQUEST['constraint']), ": {$lang['strcluster']}</h2>\n";
-
-                       echo "<p>", sprintf($lang['strconfcluster'], $misc->printVal($_REQUEST['constraint'])), "</p>\n";
-
-                       echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
-                       echo "<p><input type=\"checkbox\" name=\"analyze\"", (isset($_REQUEST['analyze']) ? ' checked="checked"' : ''), " /> {$lang['stranalyze']}</p>\n";
-                       echo "<input type=\"hidden\" name=\"action\" value=\"cluster_constraint\" />\n";
-                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
-                       echo "<input type=\"hidden\" name=\"constraint\" value=\"", htmlspecialchars($_REQUEST['constraint']), "\" />\n";
-                       echo $misc->form;
-                       echo "<input type=\"submit\" name=\"cluster\" value=\"{$lang['strcluster']}\" />\n";
-                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
-                       echo "</form>\n";
-               }
-               else {
-                       $status = $data->clusterIndex($_POST['constraint'], $_POST['table']);
-                       if ($status == 0)
-                               if (isset($_POST['analyze'])) {
-                                       $status = $data->analyzeDB($_POST['table']);
-                                       if ($status == 0)
-                                               doDefault($lang['strclusteredgood'] . ' ' . $lang['stranalyzegood']);
-                                       else
-                                               doDefault($lang['stranalyzebad']);
-                               } else
-                                       doDefault($lang['strclusteredgood']);
-                       else
-                               doDefault($lang['strclusteredbad']);
-               }
-       }
-
-       function doReindex() {
-               global $data, $lang;
-
-               $status = $data->reindex('INDEX', $_REQUEST['constraint']);
-               if ($status == 0)
-                       doDefault($lang['strreindexgood']);
-               else
-                       doDefault($lang['strreindexbad']);
-       }
-
        /**
         * Confirm and then actually add a FOREIGN KEY constraint
         */
                                echo "<tr>";
                                echo "<td class=\"data1\" colspan=\"3\"><select name=\"target\">";
                                while (!$tables->EOF) {
-                                       $key = array('schemaname' => $tables->f['schemaname'], 'tablename' => $tables->f['tablename']);
+                                       $key = array('schemaname' => $tables->f['nspname'], 'tablename' => $tables->f['relname']);
                                        $key = serialize($key);
                                        echo "<option value=\"", htmlspecialchars($key), "\">";
-                                       if ($data->hasSchemas() && $tables->f['schemaname'] != $_REQUEST['schema']) {
-                                                       echo htmlspecialchars($tables->f['schemaname']), '.';
+                                       if ($data->hasSchemas() && $tables->f['nspname'] != $_REQUEST['schema']) {
+                                                       echo htmlspecialchars($tables->f['nspname']), '.';
                                        }
-                                       echo htmlspecialchars($tables->f['tablename']), "</option>\n";
+                                       echo htmlspecialchars($tables->f['relname']), "</option>\n";
                                        $tables->moveNext();    
                                }
                                echo "</select>\n";
                global $PHP_SELF;
                global $lang;
 
-               function cnPre(&$rowdata, $actions) {
+               function cnPre(&$rowdata) {
                        global $data, $lang;
                        if (is_null($rowdata->f['consrc'])) {
                                $atts = &$data->getAttributeNames($_REQUEST['table'], explode(' ', $rowdata->f['indkey']));
                        } else {
                                $rowdata->f['+definition'] = $rowdata->f['consrc'];
                        }
-                       
-                       if ($rowdata->f['contype'] == 'u' || $rowdata->f['contype'] == 'p') {
-                               $rowdata->f['+clustered'] = $rowdata->f['indisclustered'];
-                               //$rowdata->f['+clustered'] = $data->phpBool($rowdata->f['indisclustered']) ? $lang['stryes'] : $lang['strno'];
-                       } else {
-                               $rowdata->f['+clustered'] = '';
-                               
-                               // Disable actions for non index constraints
-                               $actions['cluster']['disable'] = true;
-                               $actions['reindex']['disable'] = true;
-                               return $actions;
-                       }
                }
                
                $misc->printTitle(array($misc->printVal($_REQUEST['database']), $misc->printVal($_REQUEST['table']), $lang['strconstraints']),'constraints');
                                'field' => '+definition',
                                'type'  => 'pre',
                        ),
-                       'clustered' => array(
-                               'title' => $lang['strclustered'],
-                               'field' => '+clustered',
-                               'type'  => 'yesno',
-                       ),
                        'actions' => array(
                                'title' => $lang['stractions'],
                        ),
                );
                
                $actions = array(
-                       'cluster' => array(
-                               'title' => $lang['strcluster'],
-                               'url'   => "{$PHP_SELF}?action=confirm_cluster_constraint&amp;{$misc->href}&amp;table=".urlencode($_REQUEST['table'])."&amp;",
-                               'vars'  => array('constraint' => 'conname'),
-                       ),
-                       'reindex' => array(
-                               'title' => $lang['strreindex'],
-                               'url'   => "{$PHP_SELF}?action=reindex&amp;{$misc->href}&amp;table=".urlencode($_REQUEST['table'])."&amp;",
-                               'vars'  => array('constraint' => 'conname'),
-                       ),
                        'drop' => array(
                                'title' => $lang['strdrop'],
-                               'url'   => "{$PHP_SELF}?action=confirm_drop_index&amp;{$misc->href}&amp;table=".urlencode($_REQUEST['table'])."&amp;",
+                               'url'   => "{$PHP_SELF}?action=confirm_drop&amp;{$misc->href}&amp;table=".urlencode($_REQUEST['table'])."&amp;",
                                'vars'  => array('constraint' => 'conname', 'type' => 'contype'),
                        ),
                );
        $misc->printNav('table','constraints');
 
        switch ($action) {
-               case 'cluster_constraint':
-                       if (isset($_POST['cluster'])) doClusterIndex(false);
-                       else doDefault();
-                       break;
-               case 'confirm_cluster_constraint':
-                       doClusterIndex(true);
-                       break;
-               case 'reindex':
-                       doReindex();
-                       break;
                case 'add_foreign_key':
                        addForeignKey(1);
                        break;
index 585a5f130a51aa6c85db172addb245c0db25df26..13006423ca700756bc3d088d4828582d4c6be8e6 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List indexes on a table
         *
-        * $Id: indexes.php,v 1.30 2004/07/13 16:13:15 jollytoad Exp $
+        * $Id: indexes.php,v 1.31 2004/07/13 16:33:53 jollytoad Exp $
         */
 
        // Include application functions
                global $data, $misc;
                global $PHP_SELF, $lang;
                
+               function indPre(&$rowdata, $actions) {
+                       global $data, $lang;
+                       
+                       if ($data->phpBool($rowdata->f['indisprimary'])) {
+                               $rowdata->f['+constraints'] = $lang['strprimarykey'];
+                               $actions['drop']['disable'] = true;
+                       }
+                       elseif ($data->phpBool($rowdata->f['indisunique'])) {
+                               $rowdata->f['+constraints'] = $lang['struniquekey'];
+                               $actions['drop']['disable'] = true;
+                       }
+                       else
+                               $rowdata->f['+constraints'] = '';
+                       
+                       return $actions;
+               }
+               
                $misc->printTitle(array($misc->printVal($_REQUEST['database']), $misc->printVal($_REQUEST['table']), $lang['strindexes']));
                $misc->printMsg($msg);
 
                                'title' => $lang['strdefinition'],
                                'field' => 'inddef',
                        ),
+                       'constraints' => array(
+                               'title' => $lang['strconstraints'],
+                               'field' => '+constraints',
+                               'type'  => 'verbatim',
+                               'params'=> array('align' => 'center'),
+                       ),
                        'clustered' => array(
                                'title' => $lang['strclustered'],
                                'field' => 'indisclustered',
                
                if (!$data->hasIsClustered()) unset($column['clustered']);
                
-               $misc->printTable($indexes, $columns, $actions, $lang['strnoindexes']);
+               $misc->printTable($indexes, $columns, $actions, $lang['strnoindexes'], 'indPre');
                
                echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create_index&{$misc->href}&table=", urlencode($_REQUEST['table']), "\">{$lang['strcreateindex']}</a></p>\n";              
        }