From: chriskl Date: Thu, 15 May 2003 14:34:46 +0000 (+0000) Subject: remove lots of duplicate funcs, more 7.1 fixes, lots of cleanups, support show_system... X-Git-Tag: REL_3-0-BETA-1~54 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=5aa024fbcb33c2b9fc814816d3d660ac0bcc9bc4;p=phppgadmin.git remove lots of duplicate funcs, more 7.1 fixes, lots of cleanups, support show_system objects --- diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index e350d218..abe1b70c 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.105 2003/05/15 10:02:22 chriskl Exp $ + * $Id: Postgres.php,v 1.106 2003/05/15 14:34:46 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -442,23 +442,13 @@ class Postgres extends BaseDB { * @return All tables, sorted alphabetically */ function &getTables() { - if (!$this->_showSystem) $where = "WHERE tablename NOT LIKE 'pg_%' "; + global $conf; + if (!$conf['show_system']) $where = "WHERE tablename NOT LIKE 'pg_%' "; else $where = ''; $sql = "SELECT tablename, tableowner FROM pg_tables {$where}ORDER BY tablename"; return $this->selectSet($sql); } - /** - * Return all information relating to a table - * @param $table The name of the table - * @return Table information - */ - function &getTableByName($table) { - $this->clean($table); - $sql = "SELECT * FROM pg_class WHERE relname='{$table}'"; - return $this->selectRow($sql); - } - /** * Retrieve the attribute definition of a table * @param $table The name of the table @@ -816,9 +806,7 @@ class Postgres extends BaseDB { * @return A recordset */ function &getSequences() { - if (!$this->_showSystem) $where = " AND relname NOT LIKE 'pg_%'"; - else $where = ''; - $sql = "SELECT c.relname, u.usename FROM pg_class c, pg_user u WHERE c.relowner=u.usesysid AND c.relkind = 'S'{$where} ORDER BY relname"; + $sql = "SELECT c.relname, u.usename FROM pg_class c, pg_user u WHERE c.relowner=u.usesysid AND c.relkind = 'S' ORDER BY relname"; return $this->selectSet( $sql ); } @@ -831,8 +819,6 @@ class Postgres extends BaseDB { function &getSequence($sequence) { $this->fieldClean($sequence); - if (!$this->_showSystem) $where = " AND relname NOT LIKE 'pg_%'"; - else $where = ''; $sql = "SELECT sequence_name AS relname, * FROM \"{$sequence}\""; return $this->selectSet( $sql ); @@ -1115,7 +1101,6 @@ class Postgres extends BaseDB { function setColumnDefault($table, $column, $default) { $this->fieldClean($table); $this->fieldClean($column); - // @@ How the heck do you clean default clause? $sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" SET DEFAULT {$default}"; @@ -1134,7 +1119,6 @@ class Postgres extends BaseDB { $sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" DROP DEFAULT"; - // @@ How do you do this? return $this->execute($sql); } @@ -1350,7 +1334,8 @@ class Postgres extends BaseDB { * @return All views */ function &getViews() { - if (!$this->_showSystem) + global $conf; + if (!$conf['show_system']) $where = "WHERE viewname NOT LIKE 'pg_%'"; else $where = ''; @@ -1657,6 +1642,13 @@ class Postgres extends BaseDB { * @return A recordet */ function &getTypes($all = false) { + global $conf; + + if ($all || $conf['show_system']) + $where = ''; + else + $where = "AND pt.oid > '{$this->_lastSystemOID}'::oid"; + $sql = "SELECT pt.typname, pu.usename AS typowner @@ -1667,6 +1659,7 @@ class Postgres extends BaseDB { pt.typowner = pu.usesysid AND typrelid = 0 AND typname !~ '^_.*' + {$where} ORDER BY typname "; @@ -2163,6 +2156,58 @@ class Postgres extends BaseDB { return $this->getFunctions(true); } + /** + * Returns all details for a particular function + * @param $func The name of the function to retrieve + * @return Function info + */ + function getFunction($function_oid) { + $this->clean($function_oid); + + $sql = "SELECT + pc.oid, + proname, + lanname as language, + format_type(prorettype, NULL) as return_type, + prosrc as source, + probin as binary, + proretset, + proisstrict, + proiscachable, + oidvectortypes(pc.proargtypes) AS arguments + FROM + pg_proc pc, pg_language pl + WHERE + pc.oid = '$function_oid'::oid + AND pc.prolang = pl.oid + "; + + return $this->selectSet($sql); + } + + /** + * Returns an array containing a function's properties + * @param $f The array of data for the function + * @return An array containing the properties + */ + function getFunctionProperties($f) { + $temp = array(); + + // Strict + if ($f['proisstrict']) + $temp[] = 'ISSTRICT'; + else + $temp[] = ''; + + // Cachable + if ($f['proiscachable']) + $temp[] = 'ISCACHABLE'; + else + $temp[] = ''; + + return $temp; + } + /** * Updates a function. Postgres 7.1 doesn't have CREATE OR REPLACE function, * so we do it with a drop and a recreate. @@ -2182,7 +2227,7 @@ class Postgres extends BaseDB { $status = $this->beginTransaction(); if ($status != 0) return -1; - $status = $this->dropFunction($funcname, false); + $status = $this->dropFunction("$funcname({$args})", false); if ($status != 0) { $this->rollbackTransaction(); return -2; @@ -2211,7 +2256,6 @@ class Postgres extends BaseDB { * @return 0 success */ function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $replace = false) { - if ($setof) return -99; $this->fieldClean($funcname); $this->clean($args); $this->fieldClean($returns); @@ -2230,7 +2274,7 @@ class Postgres extends BaseDB { $sql .= ") RETURNS {$returns} AS '\n"; $sql .= $definition; $sql .= "\n'"; - $sql .= " LANGUAGE \"{$language}\""; + $sql .= " LANGUAGE '{$language}'"; // Add flags $first = true; @@ -2324,6 +2368,7 @@ class Postgres extends BaseDB { function hasRules() { return true; } function hasLanguages() { return true; } function hasDropColumn() { return false; } + function hasSRFs() { return true; } } diff --git a/classes/database/Postgres71.php b/classes/database/Postgres71.php index 401ee90d..81c1d9f0 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.30 2003/04/30 06:49:12 chriskl Exp $ + * $Id: Postgres71.php,v 1.31 2003/05/15 14:34:47 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -38,24 +38,15 @@ class Postgres71 extends Postgres { // Table functions - /** - * Return all tables in current database - * @return All tables, sorted alphabetically - */ - function &getTables() { - if (!$this->_showSystem) $where = "WHERE tablename NOT LIKE 'pg_%' "; - else $where = ''; - $sql = "SELECT tablename, tableowner FROM pg_tables {$where}ORDER BY tablename"; - return $this->selectSet($sql); - } - /** * Returns a list of all functions in the database * @param $all If true, will find all available functions, if false just userland ones * @return All functions */ function &getFunctions($all = false) { - if ($all) + global $conf; + + if ($all || $conf['show_system']) $where = ''; else $where = "AND pc.oid > '{$this->_lastSystemOID}'::oid"; @@ -63,6 +54,7 @@ class Postgres71 extends Postgres { $sql = "SELECT pc.oid, proname, + proretset, pt.typname AS return_type, oidvectortypes(pc.proargtypes) AS arguments FROM @@ -75,6 +67,7 @@ class Postgres71 extends Postgres { SELECT pc.oid, proname, + proretset, 'OPAQUE' AS result, oidvectortypes(pc.proargtypes) AS arguments FROM @@ -90,32 +83,6 @@ class Postgres71 extends Postgres { return $this->selectSet($sql); } - /** - * Return all information relating to a table - * @param $table The name of the table - * @return Table information - */ - function &getTableByName($table) { - $this->clean($table); - $sql = "SELECT * FROM pg_class WHERE relname='{$table}'"; - return $this->selectRow($sql); - } - - /** - * Renames a table - * @param $table The table to be renamed - * @param $newName The new name for the table - * @return 0 success - */ - function renameTable($table, $newName) { - $this->clean($table); - $this->clean($newName); - $sql = "ALTER TABLE \"{$table}\" RENAME TO \"{$newName}\""; - - // @@ How do you do this? - return $this->execute($sql); - } - /** * Changes the owner of a table * @param $table The table whose owner is to change @@ -123,133 +90,14 @@ class Postgres71 extends Postgres { * @return 0 success */ function setOwnerOfTable($table, $owner) { - $this->clean($table); - $this->clean($owner); + $this->fieldClean($table); + $this->fieldClean($owner); $sql = "ALTER TABLE \"{$table}\" OWNER TO \"{$owner}\""; - // @@ How do you do this? - return $this->execute($sql); - } - - // Column Functions - - /** - * Add a new column to a table - * @param $table The table to add to - * @param $column The name of the new column - * @param $type The type of the column - * @param $size (optional) The optional size of the column (ie. 30 for varchar(30)) - * @return 0 success - */ - function addColumnToTable($table, $column, $type, $size = '') { - $this->clean($table); - $this->clean($column); - $this->clean($type); - $this->clean($size); - // @@ How the heck do you properly clean type and size? - - if ($size == '') - $sql = "ALTER TABLE \"{$table}\" ADD COLUMN \"{$column}\" {$type}"; - else - $sql = "ALTER TABLE \"{$table}\" ADD COLUMN \"{$column}\" {$type}({$size})"; - - // @@ How do you do this? - return $this->execute($sql); - } - - /** - * Sets default value of a column - * @param $table The table from which to drop - * @param $column The column name to set - * @param $default The new default value - * @return 0 success - */ - function setColumnDefault($table, $column, $default) { - $this->clean($table); - $this->clean($column); - // @@ How the heck do you clean default clause? - - $sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" SET DEFAULT {$default}"; - - // @@ How do you do this? - return $this->execute($sql); - } - - /** - * Drops default value of a column - * @param $table The table from which to drop - * @param $column The column name to drop default - * @return 0 success - */ - function dropColumnDefault($table, $column) { - $this->clean($table); - $this->clean($column); - - $sql = "ALTER TABLE \"{$table}\" ALTER COLUMN \"{$column}\" DROP DEFAULT"; - - // @@ How do you do this? - return $this->execute($sql); - } - - /** - * Sets whether or not a column can contain NULLs - * @param $table The table that contains the column - * @param $column The column to alter - * @param $state True to set null, false to set not null - * @return 0 success - * @return -1 attempt to set not null, but column contains nulls - * @return -2 transaction error - * @return -3 lock error - * @return -4 update error - */ - - /** - * Renames a column in a table - * @param $table The table containing the column to be renamed - * @param $column The column to be renamed - * @param $newName The new name for the column - * @return 0 success - */ - function renameColumn($table, $column, $newName) { - $this->clean($table); - $this->clean($column); - $this->clean($newName); - - $sql = "ALTER TABLE \"{$table}\" RENAME COLUMN \"{$column}\" TO \"{$newName}\""; - - // @@ how? return $this->execute($sql); } - // Operator functions - - /** - * Returns a list of all operators in the database - * @return All operators - */ - function getOperators() { - if (!$this->_showSystem) - $where = "WHERE po.oid > '{$this->_lastSystemOID}'::oid"; - else $where = ''; - - $sql = " - SELECT - po.oid, - po.oprname, - (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprleft) AS oprleftname, - (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprright) AS oprrightname, - (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprresult) AS resultname - FROM - pg_operator po - {$where} - ORDER BY - po.oprname, po.oid - "; - - return $this->selectSet($sql); - } - // Capabilities function hasTables() { return true; } function hasViews() { return true; } diff --git a/classes/database/Postgres72.php b/classes/database/Postgres72.php index e328dd80..324a6bf4 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.43 2003/05/15 08:59:49 chriskl Exp $ + * $Id: Postgres72.php,v 1.44 2003/05/15 14:34:47 chriskl Exp $ */ @@ -239,58 +239,6 @@ class Postgres72 extends Postgres71 { return $this->selectSet($sql); } - - /** - * Returns all details for a particular function - * @param $func The name of the function to retrieve - * @return Function info - */ - function getFunction($function_oid) { - $this->clean($function_oid); - - $sql = "SELECT - pc.oid, - proname, - lanname as language, - format_type(prorettype, NULL) as return_type, - prosrc as source, - probin as binary, - proretset, - proisstrict, - proiscachable, - oidvectortypes(pc.proargtypes) AS arguments - FROM - pg_proc pc, pg_language pl - WHERE - pc.oid = '$function_oid'::oid - AND pc.prolang = pl.oid - "; - - return $this->selectSet($sql); - } - - /** - * Returns an array containing a function's properties - * @param $f The array of data for the function - * @return An array containing the properties - */ - function getFunctionProperties($f) { - $temp = array(); - - // Strict - if ($f['proisstrict']) - $temp[] = 'ISSTRICT'; - else - $temp[] = ''; - - // Cachable - if ($f['proiscachable']) - $temp[] = 'ISCACHABLE'; - else - $temp[] = ''; - - return $temp; - } /** * Updates (replaces) a function. diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index d0663c42..b3b54820 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.44 2003/05/15 08:59:51 chriskl Exp $ + * $Id: Postgres73.php,v 1.45 2003/05/15 14:34:47 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -98,15 +98,13 @@ class Postgres73 extends Postgres72 { * @return All schemas, sorted alphabetically - but with PUBLIC first (if it exists) */ function &getSchemas() { - if (!$this->_showSystem) $and = "AND nspname NOT LIKE 'pg_%'"; + global $conf; + + if (!$conf['show_system']) $and = "AND nspname NOT LIKE 'pg_%'"; else $and = ''; $sql = "SELECT pn.nspname, pu.usename AS nspowner FROM pg_namespace pn, pg_user pu WHERE pn.nspowner = pu.usesysid - AND nspname = 'public' - UNION ALL - SELECT pn.nspname, pu.usename AS nspowner FROM pg_namespace pn, pg_user pu - WHERE pn.nspowner = pu.usesysid - AND nspname != 'public' {$and}ORDER BY nspname"; + {$and}ORDER BY nspname"; return $this->selectSet($sql); } @@ -417,35 +415,6 @@ class Postgres73 extends Postgres72 { return $this->selectSet( $sql ); } - // Operator functions - - /** - * Returns a list of all operators in the database - * @return All operators - */ - function getOperators() { - if (!$this->_showSystem) - $where = "WHERE po.oid > '{$this->_lastSystemOID}'::oid"; - else $where = ''; - - $sql = " - SELECT - po.oid, - po.oprname, - (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprleft) AS oprleftname, - (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprright) AS oprrightname, - (SELECT typname FROM pg_type pt WHERE pt.oid=po.oprresult) AS resultname - FROM - pg_operator po - {$where} - ORDER BY - po.oprname, po.oid - "; - - return $this->selectSet($sql); - - } - /** * Grabs a list of indexes for a table * @param $table The name of a table whose indexes to retrieve @@ -841,7 +810,6 @@ class Postgres73 extends Postgres72 { function hasCluster() { return true; } function hasDropBehavior() { return true; } function hasDropColumn() { return true; } - function hasSRFs() { return true; } }