* 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???
'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('');
* @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);
$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);
}
/**
* 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
// 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