Allow specification of MATCH, DEFERRABLE and INITIALLY DEFERRED on foreign keys
authorchriskl <chriskl>
Sun, 9 May 2004 06:21:19 +0000 (06:21 +0000)
committerchriskl <chriskl>
Sun, 9 May 2004 06:21:19 +0000 (06:21 +0000)
HISTORY
classes/database/Postgres.php
constraints.php

diff --git a/HISTORY b/HISTORY
index 0accbfe907e6b0c231baaca731f34ecfbb3824aa..ee8bf08f8adca40f3b3c4ce74f88340634c3cdff 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -22,6 +22,8 @@ Features
 * Fix SQL popup window to reload when the database is changed so
   that the correct page encoding is used.
 * Create view wizard (Bryan Encina)
+* Allow specification of MATCH, DEFERRABLE and INITIALLY DEFERRED on
+  foreign keys.
 
 Bugs
 * Fix pg_dump output for PostgreSQL 7.0.x and 7.1.x
index fe5be01a27cd9a6cb3975f268cba73458e30c2c7..ec2d4334220bbf1c92cb5d2c37694cbdcc4c09d1 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.197 2004/05/09 04:31:25 chriskl Exp $
+ * $Id: Postgres.php,v 1.198 2004/05/09 06:21:27 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -49,8 +49,11 @@ class Postgres extends BaseDB {
                'DELETE OR UPDATE', 'INSERT OR DELETE OR UPDATE');
        // When to execute the trigger  
        var $triggerExecTimes = array('BEFORE', 'AFTER');
-       // Foreign key actions
+       // Foreign key stuff.  First element MUST be the default.
        var $fkactions = array('NO ACTION', 'RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAULT');
+       var $fkmatches = array('MATCH SIMPLE', 'MATCH FULL');
+       var $fkdeferrable = array('NOT DEFERRABLE', 'DEFERRABLE');
+       var $fkinitial = array('INITIALLY IMMEDIATE', 'INITIALLY DEFERRED');
        // Function properties
        var $funcprops = array(array('', 'ISCACHABLE'));
        var $defaultprops = array('');
@@ -1705,11 +1708,15 @@ class Postgres extends BaseDB {
         * @param $tfields (array) An array of target fields over which to add the foreign key
         * @param $upd_action The action for updates (eg. RESTRICT)
         * @param $del_action The action for deletes (eg. RESTRICT)
+        * @param $match The match type (eg. MATCH FULL)
+        * @param $deferrable The deferrability (eg. NOT DEFERRABLE)
+        * @param $intially The initial deferrability (eg. INITIALLY IMMEDIATE)
         * @param $name (optional) The name to give the key, otherwise default name is assigned
         * @return 0 success
         * @return -1 no fields given
         */
-       function addForeignKey($table, $targschema, $targtable, $sfields, $tfields, $upd_action, $del_action, $name = '') {
+       function addForeignKey($table, $targschema, $targtable, $sfields, $tfields, $upd_action, $del_action, 
+                                                       $match, $deferrable, $initially, $name = '') {
                if (!is_array($sfields) || sizeof($sfields) == 0 ||
                        !is_array($tfields) || sizeof($tfields) == 0) return -1;
                $this->fieldClean($table);
@@ -1728,8 +1735,11 @@ class Postgres extends BaseDB {
                        $sql .= "\"{$targschema}\".";
                }               
                $sql .= "\"{$targtable}\"(\"" . join('","', $tfields) . "\") ";
-               if ($upd_action != 'NO ACTION') $sql .= " ON UPDATE {$upd_action}";
-               if ($del_action != 'NO ACTION') $sql .= " ON DELETE {$del_action}";
+               if ($match != $this->fkmatches[0]) $sql .= " {$match}";
+               if ($upd_action != $this->fkactions[0]) $sql .= " ON UPDATE {$upd_action}";
+               if ($del_action != $this->fkactions[0]) $sql .= " ON DELETE {$del_action}";
+               if ($deferrable != $this->fkdeferrable[0]) $sql .= " {$deferrable}";
+               if ($initially != $this->fkinitial[0]) $sql .= " {$initially}";
 
                return $this->execute($sql);
        }
index 82e4f4f33f8057ad68ce34b4542a26a2f79ef28c..683c9648b53b6f181e9442b1fed750b15188e575 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List constraints on a table
         *
-        * $Id: constraints.php,v 1.26 2003/12/21 02:03:14 chriskl Exp $
+        * $Id: constraints.php,v 1.27 2004/05/09 06:21:26 chriskl Exp $
         */
 
        // Include application functions
@@ -68,6 +68,9 @@
                                // Initialise variables
                                if (!isset($_POST['upd_action'])) $_POST['upd_action'] = null;
                                if (!isset($_POST['del_action'])) $_POST['del_action'] = null;
+                               if (!isset($_POST['match'])) $_POST['match'] = null;
+                               if (!isset($_POST['deferrable'])) $_POST['deferrable'] = null;
+                               if (!isset($_POST['initially'])) $_POST['initially'] = null;
                                $_REQUEST['target'] = unserialize($_REQUEST['target']);
                                
                                echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
                                foreach ($data->fkactions as $v) {
                                        echo "<option value=\"{$v}\"", ($_POST['del_action'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
                                }
-                               echo "</select>\n";                             
+                               echo "</select><br />\n";
+                               // MATCH options
+                               echo "<select name=\"match\">";
+                               foreach ($data->fkmatches as $v) {
+                                       echo "<option value=\"{$v}\"", ($_POST['match'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
+                               }
+                               echo "</select><br />\n";
+                               // DEFERRABLE options
+                               echo "<select name=\"deferrable\">";
+                               foreach ($data->fkdeferrable as $v) {
+                                       echo "<option value=\"{$v}\"", ($_POST['deferrable'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
+                               }
+                               echo "</select><br />\n";
+                               // INITIALLY options
+                               echo "<select name=\"initially\">";
+                               foreach ($data->fkinitial as $v) {
+                                       echo "<option value=\"{$v}\"", ($_POST['initially'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
+                               }
+                               echo "</select>\n";
                                echo "</td></tr>";
                                echo "</table>\n";
 
                                                || !is_array($temp) || sizeof($temp) == 0) addForeignKey(2, $lang['strfkneedscols']);
                                else {
                                        $status = $data->addForeignKey($_POST['table'], $_POST['target']['schemaname'], $_POST['target']['tablename'], 
-                                               unserialize($_POST['SourceColumnList']), $_POST['IndexColumnList'], $_POST['upd_action'], $_POST['del_action'], $_POST['name']);
+                                               unserialize($_POST['SourceColumnList']), $_POST['IndexColumnList'], $_POST['upd_action'], $_POST['del_action'], 
+                                               $_POST['match'], $_POST['deferrable'], $_POST['initially'], $_POST['name']);
                                        if ($status == 0)
                                                doDefault($lang['strfkadded']);
                                        else