/**
* Class to hold various commonly used functions
*
- * $Id: Misc.php,v 1.165 2007/11/29 23:23:56 ioguix Exp $
+ * $Id: Misc.php,v 1.166 2007/12/11 14:17:17 ioguix Exp $
*/
class Misc {
);
}
- /*
- * Output dropdown list to select server and
- * databases form the popups windows.
- * @param $onchange Javascript action to take when selections change.
- */
- function printConnection($onchange) {
- global $data, $lang, $misc;
-
- echo "<table style=\"width: 100%\"><tr><td>\n";
- echo "<label>";
- $misc->printHelp($lang['strserver'], 'pg.server');
- echo "</label>";
- echo ": <select name=\"server\" {$onchange}>\n";
-
- $servers = $misc->getServers();
- foreach($servers as $info) {
- if (empty($info['username'])) continue; // not logged on this server
- echo "<option value=\"", htmlspecialchars($info['id']), "\"",
- ((isset($_REQUEST['server']) && $info['id'] == $_REQUEST['server'])) ? ' selected="selected"' : '', ">",
- htmlspecialchars("{$info['desc']} ({$info['id']})"), "</option>\n";
- }
- echo "</select>\n</td><td style=\"text-align: right\">\n";
-
- // Get the list of all databases
- $databases = $data->getDatabases();
-
- if ($databases->recordCount() > 0) {
-
+ /*
+ * Output dropdown list to select server and
+ * databases form the popups windows.
+ * @param $onchange Javascript action to take when selections change.
+ */
+ function printConnection($onchange) {
+ global $data, $lang, $misc;
+
+ echo "<table style=\"width: 100%\"><tr><td>\n";
echo "<label>";
- $misc->printHelp($lang['strdatabase'], 'pg.database');
- echo ": <select name=\"database\" {$onchange}>\n";
+ $misc->printHelp($lang['strserver'], 'pg.server');
+ echo "</label>";
+ echo ": <select name=\"server\" {$onchange}>\n";
- //if no database was selected, user should select one
- if (!isset($_REQUEST['database']))
- echo "<option value=\"\">--</option>\n";
+ $servers = $misc->getServers();
+ foreach($servers as $info) {
+ if (empty($info['username'])) continue; // not logged on this server
+ echo "<option value=\"", htmlspecialchars($info['id']), "\"",
+ ((isset($_REQUEST['server']) && $info['id'] == $_REQUEST['server'])) ? ' selected="selected"' : '', ">",
+ htmlspecialchars("{$info['desc']} ({$info['id']})"), "</option>\n";
+ }
+ echo "</select>\n</td><td style=\"text-align: right\">\n";
- while (!$databases->EOF) {
- $dbname = $databases->fields['datname'];
- echo "<option value=\"", htmlspecialchars($dbname), "\"",
- ((isset($_REQUEST['database']) && $dbname == $_REQUEST['database'])) ? ' selected="selected"' : '', ">",
- htmlspecialchars($dbname), "</option>\n";
- $databases->moveNext();
+ // Get the list of all databases
+ $databases = $data->getDatabases();
+
+ if ($databases->recordCount() > 0) {
+
+ echo "<label>";
+ $misc->printHelp($lang['strdatabase'], 'pg.database');
+ echo ": <select name=\"database\" {$onchange}>\n";
+
+ //if no database was selected, user should select one
+ if (!isset($_REQUEST['database']))
+ echo "<option value=\"\">--</option>\n";
+
+ while (!$databases->EOF) {
+ $dbname = $databases->fields['datname'];
+ echo "<option value=\"", htmlspecialchars($dbname), "\"",
+ ((isset($_REQUEST['database']) && $dbname == $_REQUEST['database'])) ? ' selected="selected"' : '', ">",
+ htmlspecialchars($dbname), "</option>\n";
+ $databases->moveNext();
+ }
+ echo "</select></label>\n";
}
- echo "</select></label>\n";
- }
- else {
- $server_info = $misc->getServerInfo();
- echo "<input type=\"hidden\" name=\"database\" value=\"",
- htmlspecialchars($server_info['defaultdb']), "\" />\n";
+ else {
+ $server_info = $misc->getServerInfo();
+ echo "<input type=\"hidden\" name=\"database\" value=\"",
+ htmlspecialchars($server_info['defaultdb']), "\" />\n";
+ }
+
+ echo "</td></tr></table>\n";
}
-
- echo "</td></tr></table>\n";
- }
}
?>
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.316 2007/12/05 12:05:00 ioguix Exp $
+ * $Id: Postgres.php,v 1.317 2007/12/11 14:17:17 ioguix Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
$sql = "SELECT NULL AS nspname, c.relname,
(SELECT usename FROM pg_user u WHERE u.usesysid=c.relowner) AS relowner,
(SELECT description FROM pg_description pd WHERE c.oid=pd.objoid) AS relcomment,
- reltuples::bigint AS reltuples
+ reltuples::bigint AS reltuples
FROM pg_class c
WHERE c.relkind='r'
AND NOT EXISTS (SELECT 1 FROM pg_rewrite r WHERE r.ev_class = c.oid AND r.ev_type = '1')
$this->fieldClean($name);
$this->clean($comment);
/* $schema, $owner, $tablespace not supported in pg70 */
-
+
$table = $tblrs->fields['relname'];
-
+
// Comment
$status = $this->setComment('TABLE', '', $table, $comment);
if ($status != 0) {
* @return $this->_alterTable error code
*/
function alterTable($table, $name, $owner, $schema, $comment, $tablespace) {
-
+
$this->fieldClean($table);
$data = $this->getTable($table);
if ($data->recordCount() != 1)
return $this->endTransaction();
}
-
+
/**
* Removes a table from the database
* @param $table The table to drop
function getView($view) {
$this->clean($view);
- $sql = "SELECT viewname AS relname, viewowner AS relowner, definition AS vwdefinition,
+ $sql = "SELECT viewname AS relname, NULL AS nspname, viewowner AS relowner, definition AS vwdefinition,
(SELECT description FROM pg_description pd, pg_class pc
WHERE pc.oid=pd.objoid AND pc.relname=v.viewname) AS relcomment
FROM pg_views v
$status = $this->endTransaction();
return ($status == 0) ? 0 : -1;
}
+ /**
+ * Rename a view
+ * @param $view The current view's name
+ * @param $name The new view's name
+ * @return -1 Failed
+ * @return 0 success
+ */
+ function renameView($view, $name) {
+ $this->fieldClean($name);
+ $this->fieldClean($view);
+ $sql = "ALTER TABLE \"{$view}\" RENAME TO \"{$name}\"";
+ if ($this->execute($sql) != 0)
+ return -1;
+ return 0;
+ }
/**
- * Alters a view
- * @param $view The name of the view
+ * Protected method which alter a view
+ * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION
+ * @param $vwrs The view recordSet returned by getView()
* @param $name The new name for the view
* @param $owner The new owner for the view
* @param $comment The comment on the view
* @return 0 success
- * @return -1 transaction error
- * @return -2 owner error
* @return -3 rename error
* @return -4 comment error
- * @return -5 get existing view error
+ * @return -5 owner error
+ * @return -6 schema error
*/
- function alterView($view, $name, $owner, $comment) {
- $this->fieldClean($view);
+ function _alterView($vwrs, $name, $owner, $schema, $comment) {
+
$this->fieldClean($name);
- $this->fieldClean($owner);
$this->clean($comment);
- $status = $this->beginTransaction();
- if ($status != 0) {
- $this->rollbackTransaction();
- return -1;
- }
+ $view = $vwrs->fields['relname'];
// Comment
- $status = $this->setComment('VIEW', $view, '', $comment);
- if ($status != 0) {
- $this->rollbackTransaction();
+ if ($this->setComment('VIEW', $view, '', $comment) != 0)
return -4;
+
+ // Rename (only if name has changed)
+ if ($name != $view) {
+ if ($this->renameView($view, $name) != 0)
+ return -3;
}
- // Owner
- if ($this->hasAlterTableOwner() && $owner != '') {
- // Fetch existing owner
- $data = $this->getView($view);
- if ($data->recordCount() != 1) {
- $this->rollbackTransaction();
- return -5;
- }
+ return 0;
+ }
- // If owner has been changed, then do the alteration. We are
- // careful to avoid this generally as changing owner is a
- // superuser only function.
- if ($data->fields['relowner'] != $owner) {
- $sql = "ALTER TABLE \"{$view}\" OWNER TO \"{$owner}\"";
- $status = $this->execute($sql);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -2;
- }
- }
+ /**
+ * Alter table properties
+ * @param $table The name of the view
+ * @param $name The new name for the view
+ * @param $owner The new owner for the view
+ * @param $schema The new schema for the view
+ * @param $comment The comment on the view
+ * @return 0 success
+ * @return -1 transaction error
+ * @return -2 get existing view error
+ * @return $this->_alterView error code
+ */
+ function alterView($view, $name, $owner, $schema, $comment) {
+
+ $this->fieldClean($view);
+ $data = $this->getView($view);
+ if ($data->recordCount() != 1)
+ return -2;
+
+ $status = $this->beginTransaction();
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
}
- // Rename (only if name has changed)
- if ($name != $view) {
- $sql = "ALTER TABLE \"{$view}\" RENAME TO \"{$name}\"";
- $status = $this->execute($sql);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -3;
- }
+ $status = $this->_alterView($data, $name, $owner, $schema, $comment);
+
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return $status;
}
return $this->endTransaction();
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres71.php,v 1.79 2007/11/21 15:45:31 ioguix Exp $
+ * $Id: Postgres71.php,v 1.80 2007/12/11 14:17:17 ioguix Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
return $typname;
}
+ // View functions
+
+ /**
+ * Protected method which alter a view
+ * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION
+ * @param $vwrs The view recordSet returned by getView()
+ * @param $name The new name for the view
+ * @param $owner The new owner for the view
+ * @param $comment The comment on the view
+ * @return 0 success
+ * @return -3 rename error
+ * @return -4 comment error
+ * @return -5 owner error
+ * @return -6 schema error
+ */
+ function _alterView($vwrs, $name, $owner, $schema, $comment) {
+
+ $status = parent::_alterView($vwrs, $name, $owner, $schema, $comment);
+ if ($status != 0)
+ return $status;
+
+ $this->fieldClean($name);
+ // if name is not empty, view has been renamed in parent
+ $view = (!empty($name)) ? $name : $tblrs->fields['relname'];
+
+ $this->fieldClean($owner);
+ // Owner
+ if ((!empty($owner)) && ($vwrs->fields['relowner'] != $owner)) {
+ // If owner has been changed, then do the alteration. We are
+ // careful to avoid this generally as changing owner is a
+ // superuser only function.
+ $sql = "ALTER TABLE \"{$view}\" OWNER TO \"{$owner}\"";
+ $status = $this->execute($sql);
+ if ($status != 0) return -5;
+ }
+
+ return 0;
+ }
+
// Sequence functions
/**
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres72.php,v 1.92 2007/11/15 06:06:45 xzilla Exp $
+ * $Id: Postgres72.php,v 1.93 2007/12/11 14:17:17 ioguix Exp $
*/
}
// Help functions
-
+
function getHelpPages() {
include_once('./help/PostgresDoc72.php');
return $this->help_page;
function _encryptPassword($username, $password) {
return 'md5' . md5($password . $username);
}
-
+
/**
* Changes a user's password
* @param $username The username
$enc = $this->_encryptPassword($username, $password);
$this->fieldClean($username);
$this->clean($enc);
-
+
$sql = "ALTER USER \"{$username}\" WITH ENCRYPTED PASSWORD '{$enc}'";
-
+
return $this->execute($sql);
}
$this->fieldClean($username);
$this->clean($enc);
$this->clean($expiry);
- $this->fieldArrayClean($groups);
+ $this->fieldArrayClean($groups);
$sql = "CREATE USER \"{$username}\"";
if ($password != '') $sql .= " WITH ENCRYPTED PASSWORD '{$enc}'";
if (is_array($groups) && sizeof($groups) > 0) $sql .= " IN GROUP \"" . join('", "', $groups) . "\"";
if ($expiry != '') $sql .= " VALID UNTIL '{$expiry}'";
else $sql .= " VALID UNTIL 'infinity'";
-
+
return $this->execute($sql);
}
$this->fieldClean($username);
$this->clean($enc);
$this->clean($expiry);
-
+
$sql = "ALTER USER \"{$username}\"";
if ($password != '') $sql .= " WITH ENCRYPTED PASSWORD '{$enc}'";
$sql .= ($createdb) ? ' CREATEDB' : ' NOCREATEDB';
$sql .= ($createuser) ? ' CREATEUSER' : ' NOCREATEUSER';
if ($expiry != '') $sql .= " VALID UNTIL '{$expiry}'";
else $sql .= " VALID UNTIL 'infinity'";
-
+
return $this->execute($sql);
- }
+ }
/**
* Returns all available process information.
$this->clean($database);
$sql = "SELECT * FROM pg_stat_activity WHERE datname='{$database}' ORDER BY usename, procpid";
}
-
+
return $this->selectSet($sql);
}
-
+
// Table functions
/**
*/
function getTable($table) {
$this->clean($table);
-
- $sql = "SELECT pc.relname,
- pg_get_userbyid(pc.relowner) AS relowner,
- (SELECT description FROM pg_description pd
- WHERE pc.oid=pd.objoid AND objsubid = 0) AS relcomment
+
+ $sql = "SELECT pc.relname,
+ pg_get_userbyid(pc.relowner) AS relowner,
+ (SELECT description FROM pg_description pd
+ WHERE pc.oid=pd.objoid AND objsubid = 0) AS relcomment
FROM pg_class pc
WHERE pc.relname='{$table}'";
-
+
return $this->selectSet($sql);
}
/**
* Return all tables in current database
* @param $all True to fetch all tables, false for just in current schema
- * @return All tables, sorted alphabetically
+ * @return All tables, sorted alphabetically
*/
function getTables($all = false) {
global $conf;
if (!$conf['show_system'] || $all) $where = "AND c.relname NOT LIKE 'pg\\\\_%' ";
else $where = '';
-
- $sql = "SELECT NULL AS nspname, c.relname,
- (SELECT usename FROM pg_user u WHERE u.usesysid=c.relowner) AS relowner,
+
+ $sql = "SELECT NULL AS nspname, c.relname,
+ (SELECT usename FROM pg_user u WHERE u.usesysid=c.relowner) AS relowner,
(SELECT description FROM pg_description pd WHERE c.oid=pd.objoid AND objsubid = 0) AS relcomment,
reltuples::numeric
FROM pg_class c WHERE c.relkind='r' {$where}ORDER BY relname";
$this->clean($table);
$this->clean($field);
- if ($field == '') {
+ if ($field == '') {
$sql = "
SELECT
a.attname,
format_type(a.atttypid, a.atttypmod) as type, a.atttypmod,
a.attnotnull, a.atthasdef, adef.adsrc,
- -1 AS attstattarget, a.attstorage, t.typstorage, false AS attisserial,
+ -1 AS attstattarget, a.attstorage, t.typstorage, false AS attisserial,
description as comment
- FROM
+ FROM
pg_attribute a LEFT JOIN pg_attrdef adef
ON a.attrelid=adef.adrelid AND a.attnum=adef.adnum
LEFT JOIN pg_type t ON a.atttypid=t.oid
LEFT JOIN pg_description d ON (a.attrelid = d.objoid AND a.attnum = d.objsubid)
- WHERE
- a.attrelid = (SELECT oid FROM pg_class WHERE relname='{$table}')
+ WHERE
+ a.attrelid = (SELECT oid FROM pg_class WHERE relname='{$table}')
AND a.attnum > 0
ORDER BY a.attnum";
}
$sql = "
SELECT
a.attname,
- format_type(a.atttypid, a.atttypmod) as type,
- format_type(a.atttypid, NULL) as base_type,
+ format_type(a.atttypid, a.atttypmod) as type,
+ format_type(a.atttypid, NULL) as base_type,
a.atttypmod,
a.attnotnull, a.atthasdef, adef.adsrc,
- -1 AS attstattarget, a.attstorage, t.typstorage,
+ -1 AS attstattarget, a.attstorage, t.typstorage,
description as comment
- FROM
+ FROM
pg_attribute a LEFT JOIN pg_attrdef adef
ON a.attrelid=adef.adrelid AND a.attnum=adef.adnum
LEFT JOIN pg_type t ON a.atttypid=t.oid
LEFT JOIN pg_description d ON (a.attrelid = d.objoid AND a.attnum = d.objsubid)
- WHERE
- a.attrelid = (SELECT oid FROM pg_class WHERE relname='{$table}')
+ WHERE
+ a.attrelid = (SELECT oid FROM pg_class WHERE relname='{$table}')
AND a.attname = '{$field}'";
}
-
+
return $this->selectSet($sql);
}
// View functions
-
+
/**
* Returns a list of all views in the database
* @return All views
$where = '';
$sql = "SELECT viewname AS relname, viewowner AS relowner, definition AS vwdefinition,
- (SELECT description FROM pg_description pd, pg_class pc
+ (SELECT description FROM pg_description pd, pg_class pc
WHERE pc.oid=pd.objoid AND pc.relname=v.viewname AND pd.objsubid = 0) AS relcomment
FROM pg_views v
{$where}
return $this->selectSet($sql);
}
-
+
/**
* Returns all details for a particular view
* @param $view The name of the view to retrieve
*/
function getView($view) {
$this->clean($view);
-
- $sql = "SELECT viewname AS relname, viewowner AS relowner, definition AS vwdefinition,
- (SELECT description FROM pg_description pd, pg_class pc
+
+ $sql = "SELECT viewname AS relname, NULL AS nspname, viewowner AS relowner, definition AS vwdefinition,
+ (SELECT description FROM pg_description pd, pg_class pc
WHERE pc.oid=pd.objoid AND pc.relname=v.viewname AND pd.objsubid = 0) AS relcomment
FROM pg_views v
WHERE viewname='{$view}'";
-
+
return $this->selectSet($sql);
}
-
+
// Constraint functions
/**
switch ($type) {
case 'c':
- // CHECK constraint
+ // CHECK constraint
$sql = "ALTER TABLE \"{$relation}\" DROP CONSTRAINT \"{$constraint}\" RESTRICT";
-
+
return $this->execute($sql);
break;
case 'p':
case 'f':
// FOREIGN KEY constraint
return -99;
- }
+ }
}
/**
if ($tablespace != '' && $this->hasTablespaces())
$sql .= " USING INDEX TABLESPACE \"{$tablespace}\"";
-
+
return $this->execute($sql);
}
return $this->selectSet($sql);
}
-
+
/**
* Updates (replaces) a function.
* @param $function_oid The OID of the function
* @param $language The language the function is written for
* @param $flags An array of optional flags
* @param $setof True if returns a set, false otherwise
- * @param $comment The comment on the function
+ * @param $comment The comment on the function
* @return 0 success
* @return -1 transaction error
* @return -2 drop function error
$this->rollbackTransaction();
return -4;
}
-
+
return $this->endTransaction();
}
*/
function getTypes($all = false, $tabletypes = false, $domains = false) {
global $conf;
-
+
if ($all || $conf['show_system']) {
$where = '';
} else {
}
// Never show system table types
$where2 = "AND c.oid > '{$this->_lastSystemOID}'::oid";
-
+
// Create type filter
$tqry = "'c'";
if ($tabletypes)
$tqry .= ", 'r', 'v'";
-
+
$sql = "SELECT
pt.typname AS basename,
format_type(pt.oid, NULL) AS typname,
*/
function getOpClasses() {
global $conf;
-
+
if ($conf['show_system'])
$where = '';
else
$sql = "
SELECT DISTINCT
- pa.amname,
- po.opcname,
+ pa.amname,
+ po.opcname,
format_type(po.opcintype, NULL) AS opcintype,
TRUE AS opcdefault,
NULL::text AS opccomment
return $this->selectSet($sql);
}
-
+
// Administration functions
/**
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.179 2007/11/30 06:04:43 xzilla Exp $
+ * $Id: Postgres73.php,v 1.180 2007/12/11 14:17:17 ioguix Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
function getView($view) {
$this->clean($view);
- $sql = "SELECT c.relname, pg_catalog.pg_get_userbyid(c.relowner) AS relowner,
+ $sql = "SELECT c.relname, n.nspname, pg_catalog.pg_get_userbyid(c.relowner) AS relowner,
pg_catalog.pg_get_viewdef(c.oid) AS vwdefinition, pg_catalog.obj_description(c.oid, 'pg_class') AS relcomment
FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace)
WHERE (c.relname = '$view')
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres74.php,v 1.68 2007/11/21 15:45:31 ioguix Exp $
+ * $Id: Postgres74.php,v 1.69 2007/12/11 14:17:17 ioguix Exp $
*/
include_once('./classes/database/Postgres73.php');
function getView($view) {
$this->clean($view);
- $sql = "SELECT c.relname, pg_catalog.pg_get_userbyid(c.relowner) AS relowner,
+ $sql = "SELECT c.relname, n.nspname, pg_catalog.pg_get_userbyid(c.relowner) AS relowner,
pg_catalog.pg_get_viewdef(c.oid, true) AS vwdefinition, pg_catalog.obj_description(c.oid, 'pg_class') AS relcomment
FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace)
WHERE (c.relname = '$view')
/**
* PostgreSQL 8.1 support
*
- * $Id: Postgres81.php,v 1.17 2007/11/21 15:45:31 ioguix Exp $
+ * $Id: Postgres81.php,v 1.18 2007/12/11 14:17:17 ioguix Exp $
*/
include_once('./classes/database/Postgres80.php');
return $this->execute($sql);
}
+ // View functions
+
+ /**
+ * Protected method which alter a view
+ * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION
+ * @param $vwrs The view recordSet returned by getView()
+ * @param $name The new name for the view
+ * @param $owner The new owner for the view
+ * @param $comment The comment on the view
+ * @return 0 success
+ * @return -3 rename error
+ * @return -4 comment error
+ * @return -5 owner error
+ * @return -6 schema error
+ */
+ function _alterView($vwrs, $name, $owner, $schema, $comment) {
+
+ $status = parent::_alterView($vwrs, $name, $owner, $schema, $comment);
+ if ($status != 0)
+ return $status;
+
+ $this->fieldClean($name);
+ // if name is not empty, view has been renamed in parent
+ $view = (!empty($name)) ? $name : $tblrs->fields['relname'];
+
+ // Schema
+ $this->fieldClean($schema);
+ if (!empty($schema) && ($vwrs->fields['nspname'] != $schema)) {
+
+ // If tablespace has been changed, then do the alteration. We
+ // don't want to do this unnecessarily.
+ $sql = "ALTER TABLE \"{$view}\" SET SCHEMA \"{$schema}\"";
+
+ $status = $this->execute($sql);
+ if ($status != 0) return -6;
+ }
+
+ return 0;
+ }
+
// Sequence methods
/**
/**
* PostgreSQL 8.3 support
*
- * $Id: Postgres83.php,v 1.14 2007/11/30 07:56:06 xzilla Exp $
+ * $Id: Postgres83.php,v 1.15 2007/12/11 14:17:17 ioguix Exp $
*/
include_once('./classes/database/Postgres82.php');
// Views functions
- /**
- * Alters a view
- * @param $view The name of the view
- * @param $name The new name for the view
- * @param $owner The new owner for the view
- * @param $comment The comment on the view
- * @return 0 success
- * @return -1 transaction error
- * @return -2 owner error
- * @return -3 rename error
- * @return -4 comment error
- * @return -5 get existing view error
- */
- function alterView($view, $name, $owner, $comment) {
- $this->fieldClean($view);
-
- $this->fieldClean($name);
- $this->fieldClean($owner);
- $this->clean($comment);
-
- $status = $this->beginTransaction();
- if ($status != 0) {
- $this->rollbackTransaction();
- return -1;
- }
-
- // Comment
- $status = $this->setComment('VIEW', $view, '', $comment);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -4;
- }
-
- // Owner
- if ($owner != '') {
- // Fetch existing owner
- $data = $this->getView($view);
- if ($data->recordCount() != 1) {
- $this->rollbackTransaction();
- return -5;
- }
-
- // If owner has been changed, then do the alteration. We are
- // careful to avoid this generally as changing owner is a
- // superuser only function.
- if ($data->fields['relowner'] != $owner) {
- $sql = "ALTER TABLE \"{$view}\" OWNER TO \"{$owner}\"";
- $status = $this->execute($sql);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -2;
- }
- }
- }
-
- // Rename (only if name has changed)
- if ($name != $view) {
- $sql = "ALTER VIEW \"{$view}\" RENAME TO \"{$name}\"";
- $status = $this->execute($sql);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -3;
- }
- }
-
- return $this->endTransaction();
- }
+ /**
+ * Rename a view
+ * @param $view The current view's name
+ * @param $name The new view's name
+ * @return -1 Failed
+ * @return 0 success
+ */
+ function renameView($view, $name) {
+ $this->fieldClean($name);
+ $this->fieldClean($view);
+ $sql = "ALTER VIEW \"{$view}\" RENAME TO \"{$name}\"";
+ if ($this->execute($sql) != 0)
+ return -1;
+ return 0;
+ }
// Indexe functions
$this->clean($table);
$sql = "SELECT
- t.tgname, pg_catalog.pg_get_triggerdef(t.oid) AS tgdef,
+ t.tgname, pg_catalog.pg_get_triggerdef(t.oid) AS tgdef,
CASE WHEN t.tgenabled = 'D' THEN FALSE ELSE TRUE END AS tgenabled, p.oid AS prooid,
p.proname || ' (' || pg_catalog.oidvectortypes(p.proargtypes) || ')' AS proproto,
ns.nspname AS pronamespace
/**
* List views in a database
*
- * $Id: viewproperties.php,v 1.33 2007/09/13 14:53:41 ioguix Exp $
+ * $Id: viewproperties.php,v 1.34 2007/12/11 14:17:17 ioguix Exp $
*/
// Include application functions
if ($view->recordCount() > 0) {
if (!isset($_POST['name'])) $_POST['name'] = $view->fields['relname'];
if (!isset($_POST['owner'])) $_POST['owner'] = $view->fields['relowner'];
+ if (!isset($_POST['newschema'])) $_POST['newschema'] = $view->fields['nspname'];
if (!isset($_POST['comment'])) $_POST['comment'] = $view->fields['relcomment'];
echo "<form action=\"viewproperties.php\" method=\"post\">\n";
echo "</select></td></tr>\n";
}
+ if ($data->hasAlterTableSchema()) {
+ $schemas = $data->getSchemas();
+ echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n";
+ echo "<td class=\"data1\"><select name=\"newschema\">";
+ while (!$schemas->EOF) {
+ $schema = $schemas->fields['nspname'];
+ echo "<option value=\"", htmlspecialchars($schema), "\"",
+ ($schema == $_POST['newschema']) ? ' selected="selected"' : '', ">", htmlspecialchars($schema), "</option>\n";
+ $schemas->moveNext();
+ }
+ echo "</select></td></tr>\n";
+ }
+
echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
echo "<td class=\"data1\">";
echo "<textarea rows=\"3\" cols=\"32\" name=\"comment\">",
else echo "<p>{$lang['strnodata']}</p>\n";
}
else{
- global $data, $lang, $_reload_browser;
+ global $data, $lang, $_reload_browser, $misc;
// For databases that don't allow owner change
if (!isset($_POST['owner'])) $_POST['owner'] = '';
- $status = $data->alterView($_POST['view'], $_POST['name'], $_POST['owner'], $_POST['comment']);
+ if (!isset($_POST['newschema'])) $_POST['newschema'] = null;
+
+ $status = $data->alterView($_POST['view'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']);
if ($status == 0) {
// If view has been renamed, need to change to the new name and
// reload the browser frame.
// Force a browser reload
$_reload_browser = true;
}
+ // If schema has changed, need to change to the new schema and reload the browser
+ if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) {
+ // Jump them to the new sequence schema
+ $misc->setCurrentSchema($_POST['newschema']);
+ $_reload_browser = true;
+ }
doDefault($lang['strviewaltered']);
}
else doAlter(true, $lang['strviewalteredbad']);