* Allow renaming functions when backend supports it
* Views are now more like tables. They are listed in the browser,
you can view the virtual columns of the view and see column defaults.
+ Columns in view can also be renamed and have defaults set.
Bugs
* Fix pg_dump output for PostgreSQL 7.0.x and 7.1.x
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.200 2004/05/09 09:10:04 chriskl Exp $
+ * $Id: Postgres.php,v 1.201 2004/05/12 15:30:00 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
/**
* Given an array of attnums and a relation, returns an array mapping
- * atttribute number to attribute name.
+ * atttribute number to attribute name. Relation could be a table OR
+ * a view.
* @param $table The table to get attributes for
* @param $atts An array of attribute numbers
* @return An array mapping attnum to attname
}
/**
- * Alters a column in a table
+ * Alters a column in a table OR view
* @param $table The table in which the column resides
* @param $column The column to alter
* @param $name The new name for the column
* @param $notnull (boolean) True if not null, false otherwise
+ * @param $oldnotnull (boolean) True if column is already not null, false otherwise
* @param $default The new default for the column
* @param $olddefault The old default for the column
* @param $comment Comment for the column
* @return -3 rename column error
* @return -4 comment error
*/
- function alterColumn($table, $column, $name, $notnull, $default, $olddefault, $comment) {
+ function alterColumn($table, $column, $name, $notnull, $oldnotnull, $default, $olddefault, $comment) {
$this->clean($comment);
$this->beginTransaction();
// @@ NEED TO HANDLE "NESTED" TRANSACTION HERE
- $status = $this->setColumnNull($table, $column, !$notnull);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -1;
+ if ($notnull != $oldnotnull) {
+ $status = $this->setColumnNull($table, $column, !$notnull);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
}
-
+
// Set default, if it has changed
if ($default != $olddefault) {
if ($default == '')
}
}
- $status = $this->setComment('COLUMN', ($column != $name) ? $name: $column, $table, $comment);
+ $status = $this->setComment('COLUMN', $column, $table, $comment);
if ($status != 0) {
$this->rollbackTransaction();
return -4;
/**
* List tables in a database
*
- * $Id: tblproperties.php,v 1.43 2004/05/08 14:45:10 chriskl Exp $
+ * $Id: tblproperties.php,v 1.44 2004/05/12 15:30:00 chriskl Exp $
*/
// Include application functions
// Output table header
echo "<table>\n<tr>";
- echo "<tr><th class=\"data required\">{$lang['strname']}</th><th class=\"data required\">{$lang['strtype']}</th><th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>";
+ echo "<tr><th class=\"data required\">{$lang['strname']}</th><th class=\"data required\">{$lang['strtype']}</th>";
+ echo "<th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>";
$column = &$data->getTableAttributes($_REQUEST['table'], $_REQUEST['column']);
$column->f['attnotnull'] = $data->phpBool($column->f['attnotnull']);
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
echo "<input type=\"hidden\" name=\"column\" value=\"", htmlspecialchars($_REQUEST['column']), "\" />\n";
echo "<input type=\"hidden\" name=\"olddefault\" value=\"", htmlspecialchars($_REQUEST['olddefault']), "\" />\n";
+ if ($column->f['attnotnull']) echo "<input type=\"hidden\" name=\"oldnotnull\" value=\"on\" />\n";
echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
echo "</form>\n";
}
$status = $data->alterColumn($_REQUEST['table'], $_REQUEST['column'], $_REQUEST['field'],
- isset($_REQUEST['notnull']), $_REQUEST['default'], $_REQUEST['olddefault'],$_REQUEST['comment']);
+ isset($_REQUEST['notnull']), isset($_REQUEST['oldnotnull']), $_REQUEST['default'],
+ $_REQUEST['olddefault'],$_REQUEST['comment']);
if ($status == 0)
doDefault($lang['strcolumnaltered']);
else {
/**
* List views in a database
*
- * $Id: viewproperties.php,v 1.1 2004/05/10 15:22:00 chriskl Exp $
+ * $Id: viewproperties.php,v 1.2 2004/05/12 15:30:00 chriskl Exp $
*/
// Include application functions
echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=edit&{$misc->href}&view=",
urlencode($_REQUEST['view']), "\">{$lang['stralter']}</a></p>\n";
}
+
+ /**
+ * Displays a screen where they can alter a column in a view
+ */
+ function doProperties($msg = '') {
+ global $data, $misc;
+ global $PHP_SELF, $lang;
+
+ if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1;
+
+ switch ($_REQUEST['stage']) {
+ case 1:
+ global $lang;
+
+ echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['straltercolumn']}: ",
+ $misc->printVal($_REQUEST['column']), "</h2>\n";
+ $misc->printMsg($msg);
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+
+ // Output view header
+ echo "<table>\n<tr>";
+ echo "<tr><th class=\"data required\">{$lang['strname']}</th><th class=\"data required\">{$lang['strtype']}</th>";
+ echo "<th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>";
+
+ $column = &$data->getTableAttributes($_REQUEST['view'], $_REQUEST['column']);
+
+ if (!isset($_REQUEST['default'])) {
+ $_REQUEST['field'] = $column->f['attname'];
+ $_REQUEST['default'] = $_REQUEST['olddefault'] = $column->f['adsrc'];
+ $_REQUEST['comment'] = $column->f['comment'];
+ }
+
+ echo "<tr><td><input name=\"field\" size=\"32\" value=\"",
+ htmlspecialchars($_REQUEST['field']), "\" /></td>";
+ echo "<td>", $misc->printVal($data->formatType($column->f['type'], $column->f['atttypmod'])), "</td>";
+ echo "<td><input name=\"default\" size=\"20\" value=\"",
+ htmlspecialchars($_REQUEST['default']), "\" /></td>";
+ echo "<td><input name=\"comment\" size=\"60\" value=\"",
+ htmlspecialchars($_REQUEST['comment']), "\" /></td>";
+
+ echo "</table>\n";
+ echo "<p><input type=\"hidden\" name=\"action\" value=\"properties\" />\n";
+ echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
+ echo $misc->form;
+ echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"column\" value=\"", htmlspecialchars($_REQUEST['column']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"olddefault\" value=\"", htmlspecialchars($_REQUEST['olddefault']), "\" />\n";
+ echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
+ echo "</form>\n";
+
+ break;
+ case 2:
+ global $data, $lang;
+
+ // Check inputs
+ if (trim($_REQUEST['field']) == '') {
+ $_REQUEST['stage'] = 1;
+ doProperties($lang['strfieldneedsname']);
+ return;
+ }
+
+ $status = $data->alterColumn($_REQUEST['view'], $_REQUEST['column'], $_REQUEST['field'],
+ false, false, $_REQUEST['default'], $_REQUEST['olddefault'],$_REQUEST['comment']);
+ if ($status == 0)
+ doDefault($lang['strcolumnaltered']);
+ else {
+ $_REQUEST['stage'] = 1;
+ doProperties($lang['strcolumnalteredbad']);
+ return;
+ }
+ break;
+ default:
+ echo "<p>{$lang['strinvalidparam']}</p>\n";
+ }
+ }
/**
* Show view definition and virtual columns
case 'definition':
doDefinition();
break;
+ case 'properties':
+ if (isset($_POST['cancel'])) doDefault();
+ else doProperties();
+ break;
case 'drop':
if (isset($_POST['drop'])) doDrop(false);
else doDefault();