/**
* 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";
* 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???
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
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
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
function hasIndicies() { return true; }
function hasRules() { return true; }
function hasLanguages() { return true; }
+ function hasDropColumn() { return false; }
}
* 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 $
*/
* 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;
+ }
}
/**
* 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???
* 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);
function hasConversions() { return true; }
function hasCluster() { return true; }
function hasDropBehavior() { return true; }
+ function hasDropColumn() { return true; }
}
/**
* 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++;
/**
* 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++;