ability to create unique and partial indexes
authorchriskl <chriskl>
Tue, 12 Aug 2003 08:11:08 +0000 (08:11 +0000)
committerchriskl <chriskl>
Tue, 12 Aug 2003 08:11:08 +0000 (08:11 +0000)
HISTORY
indexes.php

diff --git a/HISTORY b/HISTORY
index 6ada01c36a5ec91eba307575f94524013cfef380..0d33c78d9807d57b2a44ffd5e72ed81027ea047d 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -25,6 +25,7 @@ Features:
 * Refresh feature on table browse
 * Support better formatted view dumps in 7.4
 * When browsing data, numeric types are aligned right
+* Ability to create unique and partial indexes
 
 Bug Fixes:
 * Lots of NULL value in table dump fixes (XML format changed slightly)
@@ -32,6 +33,7 @@ Bug Fixes:
 * Support zero column tables
 * Correctly display the contents of bytea fields
 * Consider information_schema to be a system object
+* Remember fields if index creation fails
 
 Version 3.0
 -----------
index f8907b99128b0c755fe1ad64cf9b8890300b2a5b..6d81f5ad30b8a2b45658e7017bcc13cd7ebf6158 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List indexes on a table
         *
-        * $Id: indexes.php,v 1.15 2003/07/31 08:28:03 chriskl Exp $
+        * $Id: indexes.php,v 1.16 2003/08/12 08:11:08 chriskl Exp $
         */
 
        // Include application functions
                global $PHP_SELF, $lang;
 
                if (!isset($_POST['formIndexName'])) $_POST['formIndexName'] = '';
+               if (!isset($_POST['formIndexType'])) $_POST['formIndexType'] = null;
                if (!isset($_POST['formCols'])) $_POST['formCols'] = '';
+               if (!isset($_POST['formWhere'])) $_POST['formWhere'] = '';              
 
-               echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strindexes']} : {$lang['strcreateindex']} </h2>\n";
+               echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strindexes']}: {$lang['strcreateindex']} </h2>\n";
                $misc->printMsg($msg);
 
                $attrs = &$localData->getTableAttributes($_REQUEST['table']);
                $buttonRemove->set_attribute("onclick", "buttonPressed(this);");                
                $buttonRemove->set_attribute("type", "button");
 
-               $selTypes = new XHTML_select("formIndexType");
-               $selTypes->set_data($localData->typIndexes);
-                               
                echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";
 
 
                echo "<table>\n";
                echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strindexname']}</th></tr>";
                echo "<tr>";
-               echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"formIndexName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>";
+               echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"formIndexName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
+                       htmlspecialchars($_POST['formIndexName']), "\" /></td></tr>";
                echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th>";
                echo "<th class=\"data\">{$lang['strindexcolumnlist']}</th></tr>\n";
                echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
                echo "<table> \n";
                echo "<tr>";
                echo "<th class=\"data\">{$lang['strindextype']}</th>";
-               echo "<td>" . $selTypes->fetch() . "</td>";
+               echo "<td class=\"data1\"><select name=\"formIndexType\">";
+               foreach ($localData->typIndexes as $v) {
+                       echo "<option value=\"", htmlspecialchars($v), "\"",
+                               ($v == $_POST['formIndexType']) ? ' selected="selected"' : '', ">", htmlspecialchars($v), "</option>\n";
+               }
+               echo "</select></td></tr>\n";                           
+               echo "</tr>";
+               echo "<tr>";
+               echo "<th class=\"data\">{$lang['strunique']}</th>";
+               echo "<td class=\"data1\"><input type=\"checkbox\" name=\"formUnique\"", (isset($_POST['formUnique']) ? 'checked="checked"' : ''), " /></td>";
+               echo "</tr>";
+               echo "<tr>";
+               echo "<th class=\"data\">{$lang['strwhere']}</th>";
+               echo "<td class=\"data1\">(<input name=\"formWhere\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
+                       htmlspecialchars($_POST['formWhere']), "\" />)</td>";
                echo "</tr>";
                echo "</table>";
-               
 
                echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_index\" />\n";
                echo $misc->form;
                echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
-               echo "<input type=reset value=\"{$lang['strreset']}\" /></p>\n";
+               echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
                echo "</form>\n";
-               
-               echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}&table=", urlencode($_REQUEST['table']), 
-                       "\">{$lang['strshowallindexes']}</a></p>\n";
        }
 
        /**
                
                // Check that they've given a name and at least one column
                if ($_POST['formIndexName'] == '') doCreateIndex($lang['strindexneedsname']);
-               elseif ($_POST['IndexColumnList'] == '') doCreate($lang['strindexneedscols']);
+               elseif (!isset($_POST['IndexColumnList']) || $_POST['IndexColumnList'] == '') doCreateIndex($lang['strindexneedscols']);
                else {
-                       $status = $localData->createIndex($_POST['formIndexName'], $_POST['table'], $_POST['IndexColumnList'], $_POST['formIndexType']);
+                       $status = $localData->createIndex($_POST['formIndexName'], $_POST['table'], $_POST['IndexColumnList'], 
+                               $_POST['formIndexType'], isset($_POST['formUnique']), $_POST['formWhere']);
                        if ($status == 0)
                                doDefault($lang['strindexcreated']);
                        else
                        if ($localData->hasDropBehavior()) {
                                echo "<p><input type=\"checkbox\" name=\"cascade\" /> {$lang['strcascade']}</p>\n";
                        }
-                       echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n";
-                       echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n";
+                       echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
+                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
                        echo "</form>\n";
                }
                else {
        
        switch ($action) {
                case 'save_create_index':
-                       doSaveCreateIndex();
+                       if (isset($_POST['cancel'])) doDefault();
+                       else doSaveCreateIndex();
                        break;
                case 'create_index':
                        doCreateIndex();
                        break;
                case 'drop_index':
-                       if (isset($_POST['yes'])) doDropIndex(false);
+                       if (isset($_POST['drop'])) doDropIndex(false);
                        else doDefault();
                        break;
                case 'confirm_drop_index':