From: ioguix Date: Tue, 11 Dec 2007 14:17:17 +0000 (+0000) Subject: Refacto alterView + add support for schema alteration X-Git-Tag: REL_4-2-BETA-1~17 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=c8ba7796a8fe1a53ed15dad88f89dc7bfb10da7b;p=phppgadmin.git Refacto alterView + add support for schema alteration --- diff --git a/classes/Misc.php b/classes/Misc.php index 3b267cb8..6bd9462c 100644 --- a/classes/Misc.php +++ b/classes/Misc.php @@ -2,7 +2,7 @@ /** * 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 { @@ -2015,58 +2015,58 @@ ); } - /* - * 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 "
\n"; - echo ""; - echo ": \n\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 "
\n"; echo "\n"; - while (!$databases->EOF) { - $dbname = $databases->fields['datname']; - echo "\n"; - $databases->moveNext(); + // Get the list of all databases + $databases = $data->getDatabases(); + + if ($databases->recordCount() > 0) { + + echo "\n"; } - echo "\n"; - } - else { - $server_info = $misc->getServerInfo(); - echo "\n"; + else { + $server_info = $misc->getServerInfo(); + echo "\n"; + } + + echo "
\n"; } - - echo "
\n"; - } } ?> diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index 562ea679..f5fb4c07 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -4,7 +4,7 @@ * 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??? @@ -646,7 +646,7 @@ class Postgres extends ADODB_base { $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') @@ -869,9 +869,9 @@ class Postgres extends ADODB_base { $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) { @@ -906,7 +906,7 @@ class Postgres extends ADODB_base { * @return $this->_alterTable error code */ function alterTable($table, $name, $owner, $schema, $comment, $tablespace) { - + $this->fieldClean($table); $data = $this->getTable($table); if ($data->recordCount() != 1) @@ -927,7 +927,7 @@ class Postgres extends ADODB_base { return $this->endTransaction(); } - + /** * Removes a table from the database * @param $table The table to drop @@ -2539,7 +2539,7 @@ class Postgres extends ADODB_base { 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 @@ -2630,69 +2630,85 @@ class Postgres extends ADODB_base { $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(); diff --git a/classes/database/Postgres71.php b/classes/database/Postgres71.php index 4fc3db76..247409b3 100644 --- a/classes/database/Postgres71.php +++ b/classes/database/Postgres71.php @@ -4,7 +4,7 @@ * 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??? @@ -228,6 +228,45 @@ class Postgres71 extends Postgres { 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 /** diff --git a/classes/database/Postgres72.php b/classes/database/Postgres72.php index eb33a06d..16d64b8c 100644 --- a/classes/database/Postgres72.php +++ b/classes/database/Postgres72.php @@ -4,7 +4,7 @@ * 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 $ */ @@ -41,7 +41,7 @@ class Postgres72 extends Postgres71 { } // Help functions - + function getHelpPages() { include_once('./help/PostgresDoc72.php'); return $this->help_page; @@ -57,7 +57,7 @@ class Postgres72 extends Postgres71 { function _encryptPassword($username, $password) { return 'md5' . md5($password . $username); } - + /** * Changes a user's password * @param $username The username @@ -68,9 +68,9 @@ class Postgres72 extends Postgres71 { $enc = $this->_encryptPassword($username, $password); $this->fieldClean($username); $this->clean($enc); - + $sql = "ALTER USER \"{$username}\" WITH ENCRYPTED PASSWORD '{$enc}'"; - + return $this->execute($sql); } @@ -89,7 +89,7 @@ class Postgres72 extends Postgres71 { $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}'"; @@ -98,7 +98,7 @@ class Postgres72 extends Postgres71 { 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); } @@ -116,16 +116,16 @@ class Postgres72 extends Postgres71 { $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. @@ -139,10 +139,10 @@ class Postgres72 extends Postgres71 { $this->clean($database); $sql = "SELECT * FROM pg_stat_activity WHERE datname='{$database}' ORDER BY usename, procpid"; } - + return $this->selectSet($sql); } - + // Table functions /** @@ -181,29 +181,29 @@ class Postgres72 extends Postgres71 { */ 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"; @@ -220,21 +220,21 @@ class Postgres72 extends Postgres71 { $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"; } @@ -242,27 +242,27 @@ class Postgres72 extends Postgres71 { $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 @@ -276,7 +276,7 @@ class Postgres72 extends Postgres71 { $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} @@ -284,7 +284,7 @@ class Postgres72 extends Postgres71 { return $this->selectSet($sql); } - + /** * Returns all details for a particular view * @param $view The name of the view to retrieve @@ -292,16 +292,16 @@ class Postgres72 extends Postgres71 { */ 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 /** @@ -319,9 +319,9 @@ class Postgres72 extends Postgres71 { switch ($type) { case 'c': - // CHECK constraint + // CHECK constraint $sql = "ALTER TABLE \"{$relation}\" DROP CONSTRAINT \"{$constraint}\" RESTRICT"; - + return $this->execute($sql); break; case 'p': @@ -332,7 +332,7 @@ class Postgres72 extends Postgres71 { case 'f': // FOREIGN KEY constraint return -99; - } + } } /** @@ -383,7 +383,7 @@ class Postgres72 extends Postgres71 { if ($tablespace != '' && $this->hasTablespaces()) $sql .= " USING INDEX TABLESPACE \"{$tablespace}\""; - + return $this->execute($sql); } @@ -422,7 +422,7 @@ class Postgres72 extends Postgres71 { return $this->selectSet($sql); } - + /** * Updates (replaces) a function. * @param $function_oid The OID of the function @@ -434,7 +434,7 @@ class Postgres72 extends Postgres71 { * @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 @@ -478,7 +478,7 @@ class Postgres72 extends Postgres71 { $this->rollbackTransaction(); return -4; } - + return $this->endTransaction(); } @@ -493,7 +493,7 @@ class Postgres72 extends Postgres71 { */ function getTypes($all = false, $tabletypes = false, $domains = false) { global $conf; - + if ($all || $conf['show_system']) { $where = ''; } else { @@ -501,12 +501,12 @@ class Postgres72 extends Postgres71 { } // 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, @@ -534,7 +534,7 @@ class Postgres72 extends Postgres71 { */ function getOpClasses() { global $conf; - + if ($conf['show_system']) $where = ''; else @@ -542,8 +542,8 @@ class Postgres72 extends Postgres71 { $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 @@ -557,7 +557,7 @@ class Postgres72 extends Postgres71 { return $this->selectSet($sql); } - + // Administration functions /** diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index d8d962f1..31bc7661 100644 --- a/classes/database/Postgres73.php +++ b/classes/database/Postgres73.php @@ -4,7 +4,7 @@ * 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??? @@ -634,7 +634,7 @@ class Postgres73 extends Postgres72 { 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') diff --git a/classes/database/Postgres74.php b/classes/database/Postgres74.php index 67ecdcc1..af0adcd8 100644 --- a/classes/database/Postgres74.php +++ b/classes/database/Postgres74.php @@ -4,7 +4,7 @@ * 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'); @@ -321,7 +321,7 @@ class Postgres74 extends Postgres73 { 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') diff --git a/classes/database/Postgres81.php b/classes/database/Postgres81.php index e5b7ae12..fa133a79 100644 --- a/classes/database/Postgres81.php +++ b/classes/database/Postgres81.php @@ -3,7 +3,7 @@ /** * 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'); @@ -540,6 +540,46 @@ class Postgres81 extends Postgres80 { 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 /** diff --git a/classes/database/Postgres83.php b/classes/database/Postgres83.php index 3fb93e5c..2352cda7 100644 --- a/classes/database/Postgres83.php +++ b/classes/database/Postgres83.php @@ -3,7 +3,7 @@ /** * 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'); @@ -65,73 +65,21 @@ class Postgres83 extends Postgres82 { // 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 @@ -811,7 +759,7 @@ class Postgres83 extends Postgres82 { $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 diff --git a/viewproperties.php b/viewproperties.php index 5f6863a3..d0c8f148 100755 --- a/viewproperties.php +++ b/viewproperties.php @@ -3,7 +3,7 @@ /** * 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 @@ -256,6 +256,7 @@ 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 "
\n"; @@ -282,6 +283,19 @@ echo "\n"; } + if ($data->hasAlterTableSchema()) { + $schemas = $data->getSchemas(); + echo "{$lang['strschema']}\n"; + echo "\n"; + } + echo "{$lang['strcomment']}\n"; echo ""; echo "