drop constraint for 7.2 and below. hasDropColumn() support. don't show schema and...
authorchriskl <chriskl>
Wed, 7 May 2003 06:29:53 +0000 (06:29 +0000)
committerchriskl <chriskl>
Wed, 7 May 2003 06:29:53 +0000 (06:29 +0000)
classes/Misc.php
classes/database/Postgres.php
classes/database/Postgres72.php
classes/database/Postgres73.php
constraints.php
tblproperties.php

index 4ef555a3abe48e9975d6c0b6270c4dabaa6c4d6e..ba5c21967fbb630ce00062d75f9c65d1522d47ce 100644 (file)
@@ -2,7 +2,7 @@
        /**
         * Class to hold various commonly used functions
         *
-        * $Id: Misc.php,v 1.29 2003/05/05 03:03:53 chriskl Exp $
+        * $Id: Misc.php,v 1.30 2003/05/07 06:29:54 chriskl Exp $
         */
         
        class Misc {
                 * Display the navigation header for tables
                 */
                function printDatabaseNav() {
-                       global $lang;
+                       global $lang, $data;
 
                        $vars = 'database=' . urlencode($_REQUEST['database']);
 
                        echo "<table class=\"navbar\" border=\"0\" width=\"100%\" cellpadding=\"5\" cellspacing=\"3\"><tr>\n";
-                       echo "<td width=\"20%\"><a href=\"database.php?{$vars}\">{$lang['strschemas']}</a></td>\n";
-                       echo "<td width=\"20%\"><a href=\"privileges.php?{$vars}&type=database&object=", urlencode($_REQUEST['database']), "\">{$lang['strprivileges']}</a></td>\n";
+                       // Only show schemas if available
+                       if ($data->hasSchemas()) {
+                               echo "<td width=\"20%\"><a href=\"database.php?{$vars}\">{$lang['strschemas']}</a></td>\n";
+                       }
+                       // Only show database privs if available
+                       if (isset($data->privlist['database'])) {
+                               echo "<td width=\"20%\"><a href=\"privileges.php?{$vars}&type=database&object=", urlencode($_REQUEST['database']), "\">{$lang['strprivileges']}</a></td>\n";
+                       }
                        echo "<td width=\"20%\"><a href=\"database.php?{$vars}&action=sql\">{$lang['strsql']}</a></td>\n";
                        echo "<td width=\"20%\"><a href=\"database.php?{$vars}&action=admin\">{$lang['stradmin']}</a></td>\n";
                        //echo "<td width=\"20%\"><a href=\"database.php?{$vars}&action=export\">{$lang['strexport']}</a></td></tr>\n";
index 025919cdee79700808e2f9d246a353e6b59202b5..7b4a5d01a3ab778d13b6a30579b4507618f363e9 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.94 2003/05/06 14:24:37 chriskl Exp $
+ * $Id: Postgres.php,v 1.95 2003/05/07 06:29:54 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -950,6 +950,37 @@ class Postgres extends BaseDB {
                return $this->endTransaction();
        }       
 
+       // Constraint functions
+
+       /**
+        * Removes a constraint from a relation
+        * @param $constraint The constraint to drop
+        * @param $relation The relation from which to drop
+        * @param $type The type of constraint (c, f, u or p)
+        * @param $cascade True to cascade drop, false to restrict
+        * @return 0 success
+        * @return -99 dropping foreign keys not supported
+        */
+       function dropConstraint($constraint, $relation, $type, $cascade) {
+               $this->fieldClean($constraint);
+               $this->fieldClean($relation);
+
+               switch ($type) {
+                       case 'c':
+                               // CHECK constraint             
+                               return $this->dropCheckConstraint($relation, $constraint);
+                               break;
+                       case 'p':
+                       case 'u':
+                               // PRIMARY KEY or UNIQUE constraint
+                               return $this->dropIndex($constraint, $cascade);
+                               break;
+                       case 'f':
+                               // FOREIGN KEY constraint
+                               return -99;
+               }                               
+       }
+
        /**
         * Adds a unique constraint to a table
         * @param $table The table to which to add the unique
@@ -971,20 +1002,6 @@ class Postgres extends BaseDB {
                return $this->execute($sql);
        }
 
-       /**
-        * Drops a unique constraint from a table
-        * @param $table The table from which to drop the unique
-        * @param $name The name of the unique
-        * @return 0 success
-        */
-       function dropUniqueKey($table, $name) {
-               $this->fieldClean($name);
-
-               $sql = "DROP INDEX \"{$name}\"";
-
-               return $this->execute($sql);
-       }       
-
        /**
         * Adds a foreign key constraint to a table
         * @param $table The table to which to add the foreign key
@@ -1029,20 +1046,6 @@ class Postgres extends BaseDB {
                return -99; // Not supported.
        }
 
-       /**
-        * Drops a primary key constraint from a table
-        * @param $table The table from which to drop the primary key
-        * @param $name The name of the primary key
-        * @return 0 success
-        */
-       function dropPrimaryKey($table, $name) {
-               $this->fieldClean($name);
-               
-               $sql = "DROP INDEX \"{$name}\"";
-
-               return $this->execute($sql);
-       }
-       
        /**
         * Changes the owner of a table
         * @param $table The table whose owner is to change
@@ -2289,6 +2292,7 @@ class Postgres extends BaseDB {
        function hasIndicies() { return true; }
        function hasRules() { return true; }
        function hasLanguages() { return true; }
+       function hasDropColumn() { return false; }
 
 }
 
index ab719d75f26fb0b6914329c5a68aea4cc689cdba..e825589d03e21ab22b6beae250d5433364c7fcef 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.38 2003/05/06 14:24:38 chriskl Exp $
+ * $Id: Postgres72.php,v 1.39 2003/05/07 06:29:54 chriskl Exp $
  */
 
 
@@ -124,17 +124,32 @@ class Postgres72 extends Postgres71 {
         * Removes a constraint from a relation
         * @param $constraint The constraint to drop
         * @param $relation The relation from which to drop
+        * @param $type The type of constraint (c, f, u or p)
         * @param $cascade True to cascade drop, false to restrict
         * @return 0 success
+        * @return -99 dropping foreign keys not supported
         */
-       function dropConstraint($constraint, $relation, $cascade) {
+       function dropConstraint($constraint, $relation, $type, $cascade) {
                $this->fieldClean($constraint);
                $this->fieldClean($relation);
 
-               $sql = "ALTER TABLE \"{$relation}\" DROP CONSTRAINT \"{$constraint}\" RESTRICT";
-               if ($cascade) $sql .= " CASCADE";               
-
-               return $this->execute($sql);
+               switch ($type) {
+                       case 'c':
+                               // CHECK constraint             
+                               $sql = "ALTER TABLE \"{$relation}\" DROP CONSTRAINT \"{$constraint}\" RESTRICT";
+                               if ($cascade) $sql .= " CASCADE";               
+               
+                               return $this->execute($sql);
+                               break;
+                       case 'p':
+                       case 'u':
+                               // PRIMARY KEY or UNIQUE constraint
+                               return $this->dropIndex($constraint, $cascade);
+                               break;
+                       case 'f':
+                               // FOREIGN KEY constraint
+                               return -99;
+               }                               
        }
 
        /**
index 521fa94f2cd5937d55d560c6befffa07592ef26f..857c06b6663d4804a032784836ed8dd0e07d850b 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.40 2003/05/05 14:55:08 chriskl Exp $
+ * $Id: Postgres73.php,v 1.41 2003/05/07 06:29:54 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -708,10 +708,11 @@ class Postgres73 extends Postgres72 {
         * Removes a constraint from a relation
         * @param $constraint The constraint to drop
         * @param $relation The relation from which to drop
+        * @param $type The type of constraint (c, f, u or p)
         * @param $cascade True to cascade drop, false to restrict
         * @return 0 success
         */
-       function dropConstraint($constraint, $relation, $cascade) {
+       function dropConstraint($constraint, $relation, $type, $cascade) {
                $this->fieldClean($constraint);
                $this->fieldClean($relation);
 
@@ -726,6 +727,7 @@ class Postgres73 extends Postgres72 {
        function hasConversions() { return true; }
        function hasCluster() { return true; }
        function hasDropBehavior() { return true; }
+       function hasDropColumn() { return true; }
 
 }
 
index 1d9a1061b9b80ddca8407a0aec2c6b1852cb27a2..187d248c1d8f00b9e39868da42a3430d2f4c8e1f 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List constraints on a table
         *
-        * $Id: constraints.php,v 1.15 2003/05/01 03:27:54 chriskl Exp $
+        * $Id: constraints.php,v 1.16 2003/05/07 06:29:53 chriskl Exp $
         */
 
        // Include application functions
                                htmlspecialchars($_REQUEST['table'])), "</p>\n";
 
                        echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
-                       echo "<input type=\"hidden\" name=\"action\" value=\"drop\">\n";
-                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
-                       echo "<input type=\"hidden\" name=\"constraint\" value=\"", htmlspecialchars($_REQUEST['constraint']), "\">\n";
+                       echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
+                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+                       echo "<input type=\"hidden\" name=\"constraint\" value=\"", htmlspecialchars($_REQUEST['constraint']), "\" />\n";
+                       echo "<input type=\"hidden\" name=\"type\" value=\"", htmlspecialchars($_REQUEST['type']), "\" />\n";
                        echo $misc->form;
                        // Show cascade drop option if supportd
                        if ($localData->hasDropBehavior()) {
-                               echo "<p><input type=\"checkbox\" name=\"cascade\"> {$lang['strcascade']}</p>\n";
+                               echo "<p><input type=\"checkbox\" name=\"cascade\" /> {$lang['strcascade']}</p>\n";
                        }
-                       echo "<input type=\"submit\" name=\"choice\" value=\"{$lang['stryes']}\"> <input type=\"submit\" name=\"choice\" value=\"{$lang['strno']}\">\n";
+                       echo "<input type=\"submit\" name=\"choice\" value=\"{$lang['stryes']}\" />\n";
+                       echo "<input type=\"submit\" name=\"choice\" value=\"{$lang['strno']}\" />\n";
                        echo "</form>\n";
                }
                else {
-                       $status = $localData->dropConstraint($_POST['constraint'], $_POST['table'], isset($_POST['cascade']));
+                       $status = $localData->dropConstraint($_POST['constraint'], $_POST['table'], $_POST['type'], isset($_POST['cascade']));
                        if ($status == 0)
                                doDefault($lang['strconstraintdropped']);
                        else
                                echo "</td>";
                                echo "<td class=\"data{$id}\">";
                                echo "<a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&constraint=", urlencode($constraints->f[$data->cnFields['conname']]),
-                                       "&table=", urlencode($_REQUEST['table']), "\">{$lang['strdrop']}</td></tr>\n";
+                                       "&table=", urlencode($_REQUEST['table']), "&type=", urlencode($constraints->f['contype']), "\">{$lang['strdrop']}</td></tr>\n";
 
                                $constraints->moveNext();
                                $i++;
index e029eb01ae0b3aaec36e7da969cc1cb738b2aed2..51ea9a0896ca09727196b686c5dfd316f71ed5f1 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tblproperties.php,v 1.14 2003/05/01 03:27:54 chriskl Exp $
+        * $Id: tblproperties.php,v 1.15 2003/05/07 06:29:54 chriskl Exp $
         */
 
        // Include application functions
 
                if ($attrs->recordCount() > 0) {
                        echo "<table>\n";
-                       echo "<tr><th class=\"data\">{$lang['strfield']}</th><th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th><th colspan=\"2\" class=\"data\">{$lang['stractions']}</th>\n";
+                       echo "<tr><th class=\"data\">{$lang['strfield']}</th><th class=\"data\">{$lang['strtype']}</th>";
+                       echo "<th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th>";
+                       if ($data->hasDropColumn())
+                               echo "<th colspan=\"2\" class=\"data\">{$lang['stractions']}</th>\n";
+                       else
+                               echo "<th class=\"data\">{$lang['stractions']}</th>\n";
                        $i = 0;
                        while (!$attrs->EOF) {
                                $attrs->f['attnotnull'] = $localData->phpBool($attrs->f['attnotnull']);
                                echo "<td class=\"data{$id}\">", htmlspecialchars($attrs->f['adsrc']), "</td>\n";
                                echo "<td class=\"opbutton{$id}\"><a href=\"{$PHP_SELF}?{$misc->href}&table=", urlencode($_REQUEST['table']),
                                        "&column=", urlencode($attrs->f['attname']), "&action=properties\">{$lang['strproperties']}</a></td>\n";
-                               echo "<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";
+                               if ($data->hasDropColumn()) {
+                                       echo "<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 "</tr>\n";
                                $attrs->moveNext();
                                $i++;