* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres74.php,v 1.7 2003/07/31 08:28:03 chriskl Exp $
+ * $Id: Postgres74.php,v 1.8 2003/08/01 01:45:30 chriskl Exp $
*/
include_once('classes/database/Postgres73.php');
class Postgres74 extends Postgres73 {
// Last oid assigned to a system object
- var $_lastSystemOID = 16974;
+ var $_lastSystemOID = 17137;
// Max object name length
var $_maxNameLen = 63;
$this->Postgres73($host, $port, $database, $user, $password);
}
-
// Trigger functions
/**
/**
* Adds a check constraint to a domain
- * @param $table The table to which to add the check
+ * @param $domain The domain to which to add the check
* @param $definition The definition of the check
* @param $name (optional) The name to give the check, otherwise default name is assigned
* @return 0 success
return $this->execute($sql);
}
+ /**
+ * Alters a domain
+ * @param $domain The domain to alter
+ * @param $domdefault The domain default
+ * @param $domnotnull True for NOT NULL, false otherwise
+ * @param $domowner The domain owner
+ * @return 0 success
+ * @return -1 transaction error
+ * @return -2 default error
+ * @return -3 not null error
+ * @return -4 owner error
+ */
+ function alterDomain($domain, $domdefault, $domnotnull, $domowner) {
+ $this->fieldClean($domain);
+ $this->fieldClean($domowner);
+
+ $status = $this->beginTransaction();
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ // Default
+ if ($domdefault == '')
+ $sql = "ALTER DOMAIN \"{$domain}\" DROP DEFAULT";
+ else
+ $sql = "ALTER DOMAIN \"{$domain}\" SET DEFAULT {$domdefault}";
+
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -2;
+ }
+
+ // NOT NULL
+ if ($domnotnull)
+ $sql = "ALTER DOMAIN \"{$domain}\" SET NOT NULL";
+ else
+ $sql = "ALTER DOMAIN \"{$domain}\" DROP NOT NULL";
+
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -3;
+ }
+
+ // Owner
+ $sql = "ALTER DOMAIN \"{$domain}\" OWNER TO \"{$domowner}\"";
+
+ $status = $this->execute($sql);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -4;
+ }
+
+ return $this->endTransaction();
+ }
+
// Capabilities
function hasGrantOption() { return true; }
function hasDomainConstraints() { return true; }
/**
* Manage domains in a database
*
- * $Id: domains.php,v 1.2 2003/07/31 08:28:03 chriskl Exp $
+ * $Id: domains.php,v 1.3 2003/08/01 01:45:30 chriskl Exp $
*/
// Include application functions
$PHP_SELF = $_SERVER['PHP_SELF'];
/**
- * Function to save after editing a domain
+ * Function to save after altering a domain
*/
- function doSaveEdit() {
+ function doSaveAlter() {
global $localData, $lang;
- $status = $localData->setDomain($_POST['domain'], $_POST['formDefinition']);
+ $status = $localData->alterDomain($_POST['domain'], $_POST['domdefault'],
+ isset($_POST['domnotnull']), $_POST['domowner']);
if ($status == 0)
- doProperties($lang['strdomainupdated']);
+ doProperties($lang['strdomainaltered']);
else
- doEdit($lang['strdomainupdatedbad']);
+ doAlter($lang['strdomainalteredbad']);
+ }
+
+ /**
+ * Allow altering a domain
+ */
+ function doAlter($msg = '') {
+ global $data, $localData, $misc;
+ global $PHP_SELF, $lang;
+
+ echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strdomains']}: ", $misc->printVal($_REQUEST['domain']), ": {$lang['stralter']}</h2>\n";
+ $misc->printMsg($msg);
+
+ // Fetch domain info
+ $domaindata = &$localData->getDomain($_REQUEST['domain']);
+ // Fetch all users
+ $users = &$data->getUsers();
+
+ if ($domaindata->recordCount() > 0) {
+ if (!isset($_POST['domname'])) {
+ $_POST['domtype'] = $domaindata->f['domtype'];
+ $_POST['domdefault'] = $domaindata->f['domdef'];
+ $domaindata->f['domnotnull'] = $data->phpBool($domaindata->f['domnotnull']);
+ if ($domaindata->f['domnotnull']) $_POST['domnotnull'] = 'on';
+ $_POST['domowner'] = $domaindata->f['domowner'];
+ }
+
+ // Display domain info
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<table>\n";
+ echo "<tr><th class=\"data\" width=\"70\">{$lang['strname']}</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($domaindata->f['domname']), "</td></tr>\n";
+ echo "<tr><th class=\"data\">{$lang['strtype']}</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($domaindata->f['domtype']), "</td></tr>\n";
+ echo "<tr><th class=\"data\">{$lang['strnotnull']}</th>\n";
+ echo "<td class=\"data1\"><input type=\"checkbox\" name=\"domnotnull\"", (isset($_POST['domnotnull']) ? ' checked' : ''), " /></td></tr>\n";
+ echo "<tr><th class=\"data\">{$lang['strdefault']}</th>\n";
+ echo "<td class=\"data1\"><input name=\"domdefault\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
+ htmlspecialchars($_POST['domdefault']), "\" /></td></tr>\n";
+ echo "<tr><th class=\"data\">{$lang['strowner']}</th>\n";
+ echo "<td class=\"data1\"><select name=\"domowner\">";
+ while (!$users->EOF) {
+ $uname = $users->f[$data->uFields['uname']];
+ echo "<option value=\"", htmlspecialchars($uname), "\"",
+ ($uname == $_POST['domowner']) ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n";
+ $users->moveNext();
+ }
+ echo "</select></td></tr>\n";
+ echo "</table>\n";
+ echo "<p><input type=\"hidden\" name=\"action\" value=\"save_alter\" />\n";
+ echo "<input type=\"hidden\" name=\"domain\" value=\"", htmlspecialchars($_REQUEST['domain']), "\" />\n";
+ echo $misc->form;
+ echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
+ echo "</form>\n";
+ }
+ else echo "<p>{$lang['strnodata']}</p>\n";
}
/**
echo "<td class=\"data1\">", ($domaindata->f['domnotnull'] ? 'NOT NULL' : ''), "</td></tr>\n";
echo "<tr><th class=\"data\">{$lang['strdefault']}</th>\n";
echo "<td class=\"data1\">", $misc->printVal($domaindata->f['domdef']), "</td></tr>\n";
+ echo "<tr><th class=\"data\">{$lang['strowner']}</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($domaindata->f['domowner']), "</td></tr>\n";
echo "</table>\n";
// Display domain constraints
}
else echo "<p>{$lang['strnodata']}</p>\n";
- echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}\">{$lang['strshowalldomains']}</a> |\n";
+ echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}\">{$lang['strshowalldomains']}</a>\n";
if ($data->hasDomainConstraints()) {
- echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=add_check&{$misc->href}&domain=", urlencode($_REQUEST['domain']),
- "\">{$lang['straddcheck']}</a> |\n";
+ echo "| <a class=\"navlink\" href=\"{$PHP_SELF}?action=add_check&{$misc->href}&domain=", urlencode($_REQUEST['domain']),
+ "\">{$lang['straddcheck']}</a>\n";
+ echo "| <a class=\"navlink\" href=\"$PHP_SELF?action=alter&{$misc->href}&domain=",
+ urlencode($_REQUEST['domain']), "\">{$lang['stralter']}</a>\n";
}
- echo "<a class=\"navlink\" href=\"$PHP_SELF?action=edit&{$misc->href}&domain=",
- urlencode($_REQUEST['domain']), "\">{$lang['stredit']}</a></p>\n";
+ echo "</p>\n";
}
/**
case 'confirm_drop':
doDrop(true);
break;
- case 'save_edit':
- doSaveEdit();
+ case 'save_alter':
+ if (isset($_POST['alter'])) doSaveAlter();
+ else doProperties();
break;
- case 'edit':
- doEdit();
+ case 'alter':
+ doAlter();
break;
case 'properties':
doProperties();