From 4b8acd43888688af1da0b66a09d86ba4df01f34e Mon Sep 17 00:00:00 2001 From: chriskl Date: Wed, 24 Dec 2003 11:12:20 +0000 Subject: [PATCH] add basic support for listing aggregates and opclasses. we now display ALL postgres objects --- BUGS | 5 ++- HISTORY | 1 + aggregates.php | 64 ++++++++++++++++++++++++++++++ browser.php | 31 ++++++++++++++- classes/database/BaseDB.php | 5 ++- classes/database/Postgres.php | 6 +-- classes/database/Postgres73.php | 69 ++++++++++++++++++++++++++++----- lang/english.php | 13 ++++++- lang/recoded/english.php | 13 ++++++- opclasses.php | 64 ++++++++++++++++++++++++++++++ schema.php | 4 +- 11 files changed, 253 insertions(+), 22 deletions(-) create mode 100644 aggregates.php create mode 100644 opclasses.php diff --git a/BUGS b/BUGS index 0b95d270..0b1d5b8a 100644 --- a/BUGS +++ b/BUGS @@ -7,7 +7,7 @@ fix getIndexes() and getConstraints() for < 7.3 to know about index type (eg. constraints can only be btree indexes) re-enable help system all DROP and ALTER commands MUST be fully schema-qualified otherwise you can accidentally drop stuff in pg_catalog :( -need icons for Casts and Conversions and Languages +need icons for Casts and Conversions, Languages, Aggs and OpClasses submit changes to HTML_TreeMenu maintainer test < 7.3 Find feature for all new objects fix constraint search to get domain and table constraints? @@ -18,4 +18,5 @@ investigate phpPgInfo Need to fix: * Variables and processes views for < 7.3 -* Viewing database properties is broken... +* Add aggregates and opclasses to Find feature +* Aggregate and opclass support for < 7.3 \ No newline at end of file diff --git a/HISTORY b/HISTORY index cf65e870..2458a84a 100644 --- a/HISTORY +++ b/HISTORY @@ -9,6 +9,7 @@ Features * Large speed improvements by reducing number of database connections and using external style sheet. * SQL pop-up window now defaults to the current database +* Display aggregates and operator classes Bugs * Object browser fixed for databases with no schemas diff --git a/aggregates.php b/aggregates.php new file mode 100644 index 00000000..a9409e83 --- /dev/null +++ b/aggregates.php @@ -0,0 +1,64 @@ +", $misc->printVal($_REQUEST['database']), ": {$lang['straggregates']}\n"; + $misc->printMsg($msg); + + $aggregates = &$data->getAggregates(); + + if ($aggregates->recordCount() > 0) { + echo "\n"; + echo ""; + echo "\n"; + $i = 0; + while (!$aggregates->EOF) { + $id = (($i % 2) == 0 ? '1' : '2'); + echo "\n"; + echo "\n"; + echo "\n"; + $aggregates->moveNext(); + $i++; + } + echo "
{$lang['strname']}{$lang['strtype']}
", $misc->printVal($aggregates->f['proname']), ""; + // If arg type is NULL, then we need to output "all types" + if ($aggregates->f['proargtypes'] === null) + echo $lang['stralltypes']; + else + echo $misc->printVal($aggregates->f['proargtypes']); + echo "
\n"; + } + else { + echo "

{$lang['strnoaggregates']}

\n"; + } + } + + $misc->printHeader($lang['straggregates']); + $misc->printBody(); + + switch ($action) { + default: + doDefault(); + break; + } + + $misc->printFooter(); + +?> diff --git a/browser.php b/browser.php index e62a49ee..f63a3283 100644 --- a/browser.php +++ b/browser.php @@ -5,7 +5,7 @@ * if you click on a database it shows a list of database objects in that * database. * - * $Id: browser.php,v 1.33 2003/12/17 09:11:32 chriskl Exp $ + * $Id: browser.php,v 1.34 2003/12/24 11:12:20 chriskl Exp $ */ // Include application functions @@ -126,7 +126,8 @@ } // Advanced if ($conf['show_advanced']) { - if ($data->hasTypes() || $data->hasOperators() || $data->hasConversions()) { + if ($data->hasTypes() || $data->hasOperators() || $data->hasConversions() + || $data->hasAggregates() || $data->hasOpClasses()) { $adv_node = &new HTML_TreeNode(array( 'text' => $lang['stradvanced'], 'link' => ($data->hasSchemas()) ? addslashes(htmlspecialchars("schema.php?{$querystr}&" . SID)) : null, @@ -137,6 +138,19 @@ // Add folder to schema $schemanode->addItem($adv_node); } + // Aggregates + if ($data->hasAggregates()) { + $agg_node = &new HTML_TreeNode(array( + 'text' => addslashes($lang['straggregates']), + 'link' => addslashes(htmlspecialchars("aggregates.php?{$querystr}")), + 'icon' => "../../../images/themes/{$conf['theme']}/types.png", + 'expandedIcon' => "../../../images/themes/{$conf['theme']}/types.png", + 'expanded' => false, + 'linkTarget' => 'detail')); + + // Add folder to schema + $adv_node->addItem($agg_node); + } // Types if ($data->hasTypes()) { $type_node = &new HTML_TreeNode(array( @@ -163,6 +177,19 @@ // Add folder to schema $adv_node->addItem($opr_node); } + // Operator Classes + if ($data->hasOpClasses()) { + $opc_node = &new HTML_TreeNode(array( + 'text' => addslashes($lang['stropclasses']), + 'link' => addslashes(htmlspecialchars("opclasses.php?{$querystr}")), + 'icon' => "../../../images/themes/{$conf['theme']}/operators.png", + 'expandedIcon' => "../../../images/themes/{$conf['theme']}/operators.png", + 'expanded' => false, + 'linkTarget' => 'detail')); + + // Add folder to schema + $adv_node->addItem($opc_node); + } // Conversions if ($data->hasConversions()) { $con_node = &new HTML_TreeNode(array( diff --git a/classes/database/BaseDB.php b/classes/database/BaseDB.php index 2ca304cc..be5f4547 100644 --- a/classes/database/BaseDB.php +++ b/classes/database/BaseDB.php @@ -4,7 +4,7 @@ * A class that implements the DB interface for Postgres * Note: This class uses ADODB and returns RecordSets. * - * $Id: BaseDB.php,v 1.36 2003/12/19 05:53:19 chriskl Exp $ + * $Id: BaseDB.php,v 1.37 2003/12/24 11:12:20 chriskl Exp $ */ include_once('./classes/database/ADODB_base.php'); @@ -258,7 +258,8 @@ class BaseDB extends ADODB_base { function hasPartialIndexes() { return false; } function hasCasts() { return false; } function hasFullSubqueries() { return false; } - + function hasPrepare() { return false; } + function hasOpClasses() { return false; } } ?> diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index 0b01e3d0..8dc1a13d 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.168 2003/12/17 09:11:32 chriskl Exp $ + * $Id: Postgres.php,v 1.169 2003/12/24 11:12:20 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -3388,7 +3388,7 @@ class Postgres extends BaseDB { return $this->selectSet($sql); } - + // Type conversion routines /** @@ -3425,7 +3425,7 @@ class Postgres extends BaseDB { function hasLanguages() { return true; } function hasDropColumn() { return false; } function hasSRFs() { return true; } - + function hasOpClasses() { return true; } } ?> diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index c4a645dd..9a77dd9b 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.83 2003/12/17 09:11:32 chriskl Exp $ + * $Id: Postgres73.php,v 1.84 2003/12/24 11:12:20 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -1354,15 +1354,15 @@ class Postgres73 extends Postgres72 { */ function &getConversions() { $sql = " - SELECT - c.conname, - pg_catalog.pg_encoding_to_char(c.conforencoding) AS conforencoding, + SELECT + c.conname, + pg_catalog.pg_encoding_to_char(c.conforencoding) AS conforencoding, pg_catalog.pg_encoding_to_char(c.contoencoding) AS contoencoding, - c.condefault - FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n - WHERE n.oid = c.connamespace - AND n.nspname='{$this->_schema}' - ORDER BY 1; + c.condefault + FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n + WHERE n.oid = c.connamespace + AND n.nspname='{$this->_schema}' + ORDER BY 1; "; return $this->selectSet($sql); @@ -1396,7 +1396,55 @@ class Postgres73 extends Postgres72 { "; return $this->selectSet($sql); - } + } + + // Aggregate functions + + /** + * Gets all aggregates + * @return A recordset + */ + function &getAggregates() { + $sql = " + SELECT + p.proname, + CASE p.proargtypes[0] + WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype + THEN NULL + ELSE pg_catalog.format_type(p.proargtypes[0], NULL) + END AS proargtypes + FROM pg_catalog.pg_proc p + LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace + WHERE + p.proisagg + AND n.nspname='{$this->_schema}' + ORDER BY 1, 2 + "; + + return $this->selectSet($sql); + } + + // Operator Class functions + + /** + * Gets all opclasses + * @return A recordset + */ + function &getOpClasses() { + $sql = " + SELECT + pa.amname, po.opcname, po.opcintype::pg_catalog.regtype AS opcintype, po.opcdefault + FROM + pg_catalog.pg_opclass po, pg_catalog.pg_am pa, pg_catalog.pg_namespace pn + WHERE + po.opcamid=pa.oid + AND po.opcnamespace=pn.oid + AND pn.nspname='{$this->_schema}' + ORDER BY 1,2 + "; + + return $this->selectSet($sql); + } // Capabilities function hasSchemas() { return true; } @@ -1407,6 +1455,7 @@ class Postgres73 extends Postgres72 { function hasDomains() { return true; } function hasAlterTrigger() { return true; } function hasCasts() { return true; } + function hasPrepare() { return true; } } diff --git a/lang/english.php b/lang/english.php index 55c00448..23433733 100755 --- a/lang/english.php +++ b/lang/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.123 2003/12/16 00:32:28 soranzo Exp $ + * $Id: english.php,v 1.124 2003/12/24 11:12:20 chriskl Exp $ */ // Language and character set @@ -115,6 +115,7 @@ $lang['strprocess'] = 'Process'; $lang['strprocesses'] = 'Processes'; $lang['strsetting'] = 'Setting'; + $lang['strparameters'] = 'Parameters'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; @@ -538,6 +539,16 @@ $lang['strreferringtables'] = 'Referring tables'; $lang['strparenttables'] = 'Parent tables'; $lang['strchildtables'] = 'Child tables'; + + // Aggregates + $lang['straggregates'] = 'Aggregates'; + $lang['strnoaggregates'] = 'No aggregates found.'; + $lang['stralltypes'] = '(All types)'; + + // Operator Classes + $lang['stropclasses'] = 'Op Classes'; + $lang['strnoopclasses'] = 'No operator classes found.'; + $lang['straccessmethod'] = 'Access method'; // Miscellaneous $lang['strtopbar'] = '%s running on %s:%s -- You are logged in as user "%s", %s'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index 70b29143..2b13aea1 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.75 2003/12/16 00:32:28 soranzo Exp $ + * $Id: english.php,v 1.76 2003/12/24 11:12:21 chriskl Exp $ */ // Language and character set @@ -115,6 +115,7 @@ $lang['strprocess'] = 'Process'; $lang['strprocesses'] = 'Processes'; $lang['strsetting'] = 'Setting'; + $lang['strparameters'] = 'Parameters'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; @@ -538,6 +539,16 @@ $lang['strreferringtables'] = 'Referring tables'; $lang['strparenttables'] = 'Parent tables'; $lang['strchildtables'] = 'Child tables'; + + // Aggregates + $lang['straggregates'] = 'Aggregates'; + $lang['strnoaggregates'] = 'No aggregates found.'; + $lang['stralltypes'] = '(All types)'; + + // Operator Classes + $lang['stropclasses'] = 'Op Classes'; + $lang['strnoopclasses'] = 'No operator classes found.'; + $lang['straccessmethod'] = 'Access method'; // Miscellaneous $lang['strtopbar'] = '%s running on %s:%s -- You are logged in as user "%s", %s'; diff --git a/opclasses.php b/opclasses.php new file mode 100644 index 00000000..55905b96 --- /dev/null +++ b/opclasses.php @@ -0,0 +1,64 @@ +", $misc->printVal($_REQUEST['database']), ": {$lang['stropclasses']}\n"; + $misc->printMsg($msg); + + $opclasses = &$data->getOpClasses(); + + if ($opclasses->recordCount() > 0) { + echo "\n"; + echo ""; + echo ""; + echo ""; + echo ""; + echo "\n"; + $i = 0; + while (!$opclasses->EOF) { + $opclasses->f['opcdefault'] = $data->phpBool($opclasses->f['opcdefault']); + $id = (($i % 2) == 0 ? '1' : '2'); + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + $opclasses->moveNext(); + $i++; + } + echo "
{$lang['straccessmethod']}{$lang['strname']}{$lang['strtype']}{$lang['strdefault']}
", $misc->printVal($opclasses->f['amname']), "", $misc->printVal($opclasses->f['opcname']), "", $misc->printVal($opclasses->f['opcintype']), "", (($opclasses->f['opcdefault']) ? $lang['stryes'] : $lang['strno']), "
\n"; + } + else { + echo "

{$lang['strnoopclasses']}

\n"; + } + } + + $misc->printHeader($lang['stropclasses']); + $misc->printBody(); + + switch ($action) { + default: + doDefault(); + break; + } + + $misc->printFooter(); + +?> diff --git a/schema.php b/schema.php index 658ea7cd..81616dcb 100755 --- a/schema.php +++ b/schema.php @@ -3,7 +3,7 @@ /** * Display properties of a schema * - * $Id: schema.php,v 1.12 2003/12/17 09:11:32 chriskl Exp $ + * $Id: schema.php,v 1.13 2003/12/24 11:12:20 chriskl Exp $ */ // Include application functions (no db conn) @@ -32,8 +32,10 @@ if ($conf['show_advanced']) { echo "
  • {$lang['stradvanced']}
  • \n"; echo "\n"; } -- 2.39.5