cascade drop for columns and constraints. remove unused functions. partial fix...
authorchriskl <chriskl>
Thu, 1 May 2003 03:27:54 +0000 (03:27 +0000)
committerchriskl <chriskl>
Thu, 1 May 2003 03:27:54 +0000 (03:27 +0000)
HISTORY
classes/database/ADODB_base.php
classes/database/BaseDB.php
classes/database/Postgres.php
classes/database/Postgres72.php
classes/database/Postgres73.php
constraints.php
tblproperties.php

diff --git a/HISTORY b/HISTORY
index 35ac5307930c577108b1b0a9c4aa148297068fcd..e65bf063c4804a0c63274279ba3c661522f2c43b 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -1,6 +1,11 @@
 phpPgAdmin History
 ------------------
 
+Version 3.0.0-dev-5
+-------------------
+
+* Cascade drop on columns and constraints
+
 Version 3.0.0-dev-4
 -------------------
 
@@ -17,7 +22,7 @@ Version 3.0.0-dev-3
 -------------------
 
 * French translation
-* Russion translations
+* Russian translations
 * Japanese translations
 * Trigger definitions
 * ADODB upgrade
index 3b43228e9a4d49bcd8e6bb607118036c6b8ef284..1570cc52f4537745f4ec6fa95ff2306c58d1bdf3 100644 (file)
@@ -3,7 +3,7 @@
 /*
  * Parent class of all ADODB objects.
  *
- * $Id: ADODB_base.php,v 1.11 2003/03/27 13:47:15 chriskl Exp $
+ * $Id: ADODB_base.php,v 1.12 2003/05/01 03:27:54 chriskl Exp $
  */
 
 include_once('libraries/errorhandler.inc.php');
@@ -180,9 +180,6 @@ class ADODB_base {
                                else $values = ") VALUES ('{$value}'";
                        }
                        $sql = $fields . $values . ')';
-               } else {
-                       // @@ THIS IS TOTALLY WRONG!!!
-                       $sql = "INSERT INTO \"{$table}\" DEFAULT VALUES";
                }
 
                // Check for failures
index 91baf2bb53951d288236e603e54110a06b445b4b..bb005210065c977de3389a1255fc2a40bf575f61 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: BaseDB.php,v 1.13 2003/04/30 06:35:41 chriskl Exp $
+ * $Id: BaseDB.php,v 1.14 2003/05/01 03:27:54 chriskl Exp $
  */
 
 include_once('classes/database/ADODB_base.php');
@@ -69,16 +69,34 @@ class BaseDB extends ADODB_base {
         * @return 0 success
         * @return -1 invalid parameters
         */
-       function insertRow($table, $values, $nulls) {
-               if (!is_array($values) || !is_array($nulls)) return -1;
+       function insertRow($table, $vars, $nulls) {
+               if (!is_array($vars) || !is_array($nulls)) return -1;
                // @@ WE CANNOT USE insert AS WE NEED TO NOT QUOTE SOME THINGS
                // @@ WHAT ABOUT BOOLEANS??
                else {
-                       $temp = array();
-                       foreach($values as $k => $v) {
-                               if (!isset($nulls[$k])) $temp[$k] = $v;
-                       }
-                       return $this->insert($table, $temp);
+                       $this->fieldClean($table);
+       
+                       // Build clause
+                       if (sizeof($vars) > 0) {
+                               $fields = '';
+                               $values = '';
+                               foreach($vars as $key => $value) {
+                                       $this->clean($key);
+                                       $this->clean($value);
+       
+                                       if ($fields) $fields .= ", \"{$key}\"";
+                                       else $fields = "INSERT INTO \"{$table}\" (\"{$key}\"";
+       
+                                       // Handle NULL values
+                                       if (isset($nulls[$key])) $tmp = 'NULL';
+                                       else $tmp = "'{$value}'";
+                                       
+                                       if ($values) $values .= ", {$tmp}";
+                                       else $values = ") VALUES ({$tmp}";
+                               }
+                               $sql = $fields . $values . ')';
+                       }                       
+                       return $this->execute($sql);
                }
        }
        
index 1dfa6960e41fc5314d420fd6c59d257fb63540fe..2b62add2d63aa956007b797b2fe2455139ceb886 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.88 2003/04/30 07:42:58 chriskl Exp $
+ * $Id: Postgres.php,v 1.89 2003/05/01 03:27:54 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -496,11 +496,11 @@ class Postgres extends BaseDB {
         * Drops a column from a table
         * @param $table The table from which to drop a column
         * @param $column The column to be dropped
-        * @param $behavior CASCADE or RESTRICT or empty
+        * @param $cascade True to cascade drop, false to restrict
         * @return 0 success
         * @return -99 not implemented
         */
-       function dropColumn($table, $column, $behavior) {
+       function dropColumn($table, $column, $cascade) {
                return -99;
        }
        
@@ -1091,16 +1091,6 @@ class Postgres extends BaseDB {
                return $this->execute($sql);
        }
 
-       /**
-        * Drops a column from a table
-        * @param $table The table from which to drop
-        * @param $column The column name to drop
-        * @return 0 success
-        */
-       function dropColumnFromTable($table, $column) {
-               return -99; // Not implemented
-       }
-
        /**
         * Sets default value of a column
         * @param $table The table from which to drop
index de085795174a476a5a96143d91cea003a2ba3b0b..dba7b2f4faeb52471b39cfeefa71b6580e9f9a44 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.36 2003/04/30 06:49:12 chriskl Exp $
+ * $Id: Postgres72.php,v 1.37 2003/05/01 03:27:54 chriskl Exp $
  */
 
 
@@ -124,13 +124,15 @@ 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 $cascade True to cascade drop, false to restrict
         * @return 0 success
         */
-       function dropConstraint($constraint, $relation) {
+       function dropConstraint($constraint, $relation, $cascade) {
                $this->fieldClean($constraint);
                $this->fieldClean($relation);
 
                $sql = "ALTER TABLE \"{$relation}\" DROP CONSTRAINT \"{$constraint}\" RESTRICT";
+               if ($cascade) $sql .= " CASCADE";               
 
                return $this->execute($sql);
        }
index 9fd7bdfdb2ada954f242f931114672a4509c46c7..d5eebe7b1a4f3be5bebda3368a01fac550681d22 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.38 2003/04/30 07:28:11 chriskl Exp $
+ * $Id: Postgres73.php,v 1.39 2003/05/01 03:27:54 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -331,16 +331,15 @@ class Postgres73 extends Postgres72 {
         * Drops a column from a table
         * @param $table The table from which to drop a column
         * @param $column The column to be dropped
-        * @param $behavior CASCADE or RESTRICT or empty
+        * @param $cascade True to cascade drop, false to restrict
         * @return 0 success
         */
-       function dropColumn($table, $column, $behavior) {
-               $this->clean($table);
-               $this->clean($column);
-               $this->clean($behavior);
+       function dropColumn($table, $column, $cascade) {
+               $this->fieldClean($table);
+               $this->fieldClean($column);
 
-               $sql = "ALTER TABLE \"{$table}\" DROP COLUMN \"{$column}\" " .
-                       (($behavior == 'CASCADE') ? 'CASCADE' : 'RESTRICT');
+               $sql = "ALTER TABLE \"{$table}\" DROP COLUMN \"{$column}\"";
+               if ($cascade) $sql .= " CASCADE";               
 
                return $this->execute($sql);
        }
@@ -353,42 +352,10 @@ class Postgres73 extends Postgres72 {
         * @return 0 success
         */
        function setColumnNull($table, $column, $state) {
-               $this->clean($table);
-               $this->clean($column);
-
-               $sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" " . (($state) ? 'DROP' : 'SET') . " NOT NULL";
-
-               return $this->execute($sql);
-       }
-
-       // Constraint functions
-
-       /**
-        * Drops a unique constraint from a table
-        * @param $table The table from which to drop the unique key
-        * @param $name The name of the unique key
-        * @return 0 success
-        */
-       function dropUniqueKey($table, $name) {
                $this->fieldClean($table);
-               $this->fieldClean($name);
-
-               $sql = "ALTER TABLE \"{$table}\" DROP CONSTRAINT \"{$name}\"";
+               $this->fieldClean($column);
 
-               return $this->execute($sql);
-       }
-
-       /**
-        * 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($table);
-               $this->fieldClean($name);
-
-               $sql = "ALTER TABLE \"{$table}\" DROP CONSTRAINT \"{$name}\"";
+               $sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" " . (($state) ? 'DROP' : 'SET') . " NOT NULL";
 
                return $this->execute($sql);
        }
@@ -728,13 +695,15 @@ 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 $cascade True to cascade drop, false to restrict
         * @return 0 success
         */
-       function dropConstraint($constraint, $relation) {
+       function dropConstraint($constraint, $relation, $cascade) {
                $this->fieldClean($constraint);
                $this->fieldClean($relation);
 
                $sql = "ALTER TABLE \"{$relation}\" DROP CONSTRAINT \"{$constraint}\"";
+               if ($cascade) $sql .= " CASCADE";
 
                return $this->execute($sql);
        }
index c8b51d27348457a3cdd87828c3bb482047db0d7b..1d9a1061b9b80ddca8407a0aec2c6b1852cb27a2 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List constraints on a table
         *
-        * $Id: constraints.php,v 1.14 2003/04/23 08:56:26 chriskl Exp $
+        * $Id: constraints.php,v 1.15 2003/05/01 03:27:54 chriskl Exp $
         */
 
        // Include application functions
                        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;
+                       // Show cascade drop option if supportd
+                       if ($localData->hasDropBehavior()) {
+                               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 "</form>\n";
                }
                else {
-                       $status = $localData->dropConstraint($_POST['constraint'], $_POST['table']);
+                       $status = $localData->dropConstraint($_POST['constraint'], $_POST['table'], isset($_POST['cascade']));
                        if ($status == 0)
                                doDefault($lang['strconstraintdropped']);
                        else
index 96893ab8c0cbc3db90a37d8d6a2efb24d521b59b..e029eb01ae0b3aaec36e7da969cc1cb738b2aed2 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tblproperties.php,v 1.13 2003/04/20 09:45:39 chriskl Exp $
+        * $Id: tblproperties.php,v 1.14 2003/05/01 03:27:54 chriskl Exp $
         */
 
        // Include application functions
                        echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                        echo "<input type=\"hidden\" name=\"column\" value=\"", htmlspecialchars($_REQUEST['column']), "\" />\n";
                        echo $misc->form;
-                       echo "<input type=\"submit\" name=\"choice\" value=\"{$lang['stryes']}\" /> <input type=\"submit\" name=\"choice\" value=\"{$lang['strno']}\" />\n";
+                       // Show cascade drop option if supportd
+                       if ($localData->hasDropBehavior()) {
+                               echo "<p><input type=\"checkbox\" name=\"cascade\"> {$lang['strcascade']}</p>\n";
+                       }
+                       echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" /> <input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n";
                        echo "</form>\n";
                }
                else {
-                       $status = $localData->dropColumn($_POST['table'], $_POST['column'], 'RESTRICT');
+                       $status = $localData->dropColumn($_POST['table'], $_POST['column'], isset($_POST['cascade']));
                        if ($status == 0)
                                doDefault($lang['strcolumndropped']);
                        else
                        doProperties();
                        break;
                case 'drop':
-                       if ($_POST['choice'] == "{$lang['stryes']}") doDrop(false);
+                       if (isset($_POST['yes'])) doDrop(false);
                        else doDefault();
                        break;
                case 'confirm_drop':