From f9f2a309110a3122389d6854ad59b237651c4ba8 Mon Sep 17 00:00:00 2001 From: chriskl Date: Sun, 26 Oct 2003 10:59:16 +0000 Subject: [PATCH] lots of operator stuff. add 'advanced' subfolder to left browser. fix a few bugs in html/xhtml --- BUGS | 2 +- HISTORY | 2 + browser.php | 18 +++++-- classes/database/Postgres.php | 72 ++++++++++++++++++------- classes/database/Postgres73.php | 43 +++++++++++++-- lang/english.php | 14 ++++- lang/recoded/english.php | 14 ++++- operators.php | 96 +++++++++++++++++++++++++++++++-- rules.php | 4 +- schema.php | 5 +- 10 files changed, 232 insertions(+), 38 deletions(-) diff --git a/BUGS b/BUGS index 2c79ebd4..770737ac 100644 --- a/BUGS +++ b/BUGS @@ -1,6 +1,6 @@ -choose operator on select screen 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 :( diff --git a/HISTORY b/HISTORY index 1876df41..0232dbf4 100644 --- a/HISTORY +++ b/HISTORY @@ -24,6 +24,8 @@ Bugs * BIGSERIAL missing from PostgreSQL 7.2 * Types lengths (eg. varchar(255)) weren't being displayed properly in PostgreSQL 7.0.x +* Resetting sequence on 7.1+ now restarts at 1, not 2 +* Remove deprecated column default 'now' from SQL script Translations * Afrikaans from Petri Jooste diff --git a/browser.php b/browser.php index d42ae0a7..8ec9605e 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.18 2003/09/10 01:55:52 chriskl Exp $ + * $Id: browser.php,v 1.19 2003/10/26 10:59:16 chriskl Exp $ */ // Include application functions @@ -123,6 +123,18 @@ // Add folder to schema $schemanode->addItem($dom_node); } + // Advanced + if ($data->hasTypes() || $data->hasOperators()) { + $adv_node = &new HTML_TreeNode(array( + 'text' => $lang['stradvanced'], + 'link' => addslashes(htmlspecialchars("schema.php?{$querystr}&" . SID)), + 'icon' => 'folder.gif', + 'expandedIcon' => 'folder-expanded.gif', + 'linkTarget' => 'detail')); + + // Add folder to schema + $schemanode->addItem($adv_node); + } // Types if ($data->hasTypes()) { $type_node = &new HTML_TreeNode(array( @@ -134,7 +146,7 @@ 'linkTarget' => 'detail')); // Add folder to schema - $schemanode->addItem($type_node); + $adv_node->addItem($type_node); } // Operators if ($data->hasOperators()) { @@ -147,7 +159,7 @@ 'linkTarget' => 'detail')); // Add folder to schema - $schemanode->addItem($opr_node); + $adv_node->addItem($opr_node); } } diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index df110846..f98031b8 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.158 2003/10/14 05:40:30 chriskl Exp $ + * $Id: Postgres.php,v 1.159 2003/10/26 10:59:16 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -847,9 +847,9 @@ class Postgres extends BaseDB { // If value is null, 't' or 'f'... if ($value === null || $value == 't' || $value == 'f') { echo "\n"; } else { @@ -1524,7 +1524,7 @@ class Postgres extends BaseDB { } /** - * Resets a given sequence to 1 + * Resets a given sequence to 2 (lowest possible in 7.0) * @param $sequence Sequence name * @return 0 success */ @@ -2212,28 +2212,64 @@ class Postgres extends BaseDB { return $this->selectSet($sql); } + + /** + * Returns all details for a particular operator + * @param $operator_oid The oid of the operator + * @return Function info + */ + function getOperator($operator_oid) { + $this->clean($operator_oid); + + $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, + po.oprcanhash, + (SELECT oprname FROM pg_operator po2 WHERE po2.oid=po.oprcom) AS oprcom, + (SELECT oprname FROM pg_operator po2 WHERE po2.oid=po.oprnegate) AS oprnegate, + (SELECT oprname FROM pg_operator po2 WHERE po2.oid=po.oprlsortop) AS oprlsortop, + (SELECT oprname FROM pg_operator po2 WHERE po2.oid=po.oprltcmpop) AS oprltcmpop, + (SELECT oprname FROM pg_operator po2 WHERE po2.oid=po.oprgtcmpop) AS oprgtcmpop, + po.oprcode::regproc AS oprcode, + --(SELECT proname FROM pg_proc pp WHERE pp.oid=po.oprcode) AS oprcode, + (SELECT proname FROM pg_proc pp WHERE pp.oid=po.oprrest) AS oprrest, + (SELECT proname FROM pg_proc pp WHERE pp.oid=po.oprjoin) AS oprjoin + FROM + pg_operator po + WHERE + po.oid='{$operator_oid}' + "; + return $this->selectSet($sql); + } + /** * Drops an operator - * @param $oprname The name of the operator to drop - * @param $lefttype The left type (NULL for none) - * @param $righttype The right type (NULL for none) + * @param $operator_oid The OID of the operator to drop * @param $cascade True to cascade drop, false to restrict * @return 0 success */ - function dropOperator($oprname, $lefttype, $righttype, $cascade) { - $this->fieldClean($oprname); + function dropOperator($operator_oid, $cascade) { + // Function comes in with $object as operator OID + $opr = &$this->getOperator($operator_oid); + $this->fieldClean($opr->f['oprname']); - $sql = "DROP OPERATOR \"{$oprname}\"("; - echo ($lefttype === null) ? 'NONE' : $lefttype; - echo ', '; - echo ($righttype === null) ? 'NONE' : $righttype; - echo ')'; + $sql = "DROP OPERATOR {$opr->f['oprname']} ("; + // Quoting or formatting here??? + if ($opr->f['oprleftname'] !== null) $sql .= $opr->f['oprleftname'] . ', '; + else $sql .= "NONE, "; + if ($opr->f['oprrightname'] !== null) $sql .= $opr->f['oprrightname'] . ')'; + else $sql .= "NONE)"; + if ($cascade) $sql .= " CASCADE"; - + return $this->execute($sql); } - + // User functions /** @@ -3129,7 +3165,7 @@ class Postgres extends BaseDB { /** * Returns all details for a particular function - * @param $func The name of the function to retrieve + * @param $function_oid The OID of the function to retrieve * @return Function info */ function getFunction($function_oid) { diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index 811e1ab3..5f91c6b6 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.71 2003/10/13 08:50:04 chriskl Exp $ + * $Id: Postgres73.php,v 1.72 2003/10/26 10:59:16 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -88,7 +88,7 @@ class Postgres73 extends Postgres72 { elseif (sizeof($paths) == 0) return -2; $this->fieldArrayClean($paths); - $sql = 'SET SEARCH_PATH TO "' . implode('"', $paths) . '"'; + $sql = 'SET SEARCH_PATH TO "' . implode('"', $paths) . '", pg_catalog'; return $this->execute($sql); } @@ -215,7 +215,7 @@ class Postgres73 extends Postgres72 { if (sizeof($atts) == 0) return array(); $sql = "SELECT attnum, attname FROM pg_catalog.pg_attribute WHERE - attrelid=(SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}'AND + attrelid=(SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}' AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{$this->_schema}')) AND attnum IN ('" . join("','", $atts) . "')"; @@ -1211,13 +1211,14 @@ class Postgres73 extends Postgres72 { * @return All operators */ function &getOperators() { + // We stick with the subselects here, as you cannot ORDER BY a regtype $sql = " SELECT po.oid, po.oprname, (SELECT pg_catalog.format_type(oid, NULL) FROM pg_catalog.pg_type pt WHERE pt.oid=po.oprleft) AS oprleftname, (SELECT pg_catalog.format_type(oid, NULL) FROM pg_catalog.pg_type pt WHERE pt.oid=po.oprright) AS oprrightname, - (SELECT pg_catalog.format_type(oid, NULL) FROM pg_catalog.pg_type pt WHERE pt.oid=po.oprresult) AS resultname + po.oprresult::pg_catalog.regtype AS resultname FROM pg_catalog.pg_operator po WHERE @@ -1228,7 +1229,41 @@ class Postgres73 extends Postgres72 { return $this->selectSet($sql); } + + /** + * Returns all details for a particular operator + * @param $operator_oid The oid of the operator + * @return Function info + */ + function getOperator($operator_oid) { + $this->clean($operator_oid); + + $sql = " + SELECT + po.oid, + po.oprname, + oprleft::pg_catalog.regtype AS oprleftname, + oprright::pg_catalog.regtype AS oprrightname, + oprresult::pg_catalog.regtype AS resultname, + po.oprcanhash, + oprcom::pg_catalog.regoperator AS oprcom, + oprnegate::pg_catalog.regoperator AS oprnegate, + oprlsortop::pg_catalog.regoperator AS oprlsortop, + oprrsortop::pg_catalog.regoperator AS oprrsortop, + oprltcmpop::pg_catalog.regoperator AS oprltcmpop, + oprgtcmpop::pg_catalog.regoperator AS oprgtcmpop, + po.oprcode::pg_catalog.regproc AS oprcode, + po.oprrest::pg_catalog.regproc AS oprrest, + po.oprjoin::pg_catalog.regproc AS oprjoin + FROM + pg_catalog.pg_operator po + WHERE + po.oid='{$operator_oid}' + "; + return $this->selectSet($sql); + } + // Capabilities function hasSchemas() { return true; } function hasConversions() { return true; } diff --git a/lang/english.php b/lang/english.php index c5514a3a..3cdaea75 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.115 2003/10/14 17:55:17 soranzo Exp $ + * $Id: english.php,v 1.116 2003/10/26 10:59:16 chriskl Exp $ */ // Language and character set @@ -110,6 +110,7 @@ $lang['strdownload'] = 'Download'; $lang['strinfo'] = 'Info'; $lang['stroids'] = 'OIDs'; + $lang['stradvanced'] = 'Advanced'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; @@ -488,9 +489,18 @@ $lang['strnooperator'] = 'No operator found.'; $lang['strnooperators'] = 'No operators found.'; $lang['strcreateoperator'] = 'Create operator'; - $lang['stroperatorname'] = 'Operator name'; $lang['strleftarg'] = 'Left Arg Type'; $lang['strrightarg'] = 'Right Arg Type'; + $lang['strcommutator'] = 'Commutator'; + $lang['strnegator'] = 'Negator'; + $lang['strrestrict'] = 'Restrict'; + $lang['strjoin'] = 'Join'; + $lang['strhashes'] = 'Hashes'; + $lang['strmerges'] = 'Merges'; + $lang['strleftsort'] = 'Left sort'; + $lang['strrightsort'] = 'Right sort'; + $lang['strlessthan'] = 'Less than'; + $lang['strgreaterthan'] = 'Greater than'; $lang['stroperatorneedsname'] = 'You must give a name for your operator.'; $lang['stroperatorcreated'] = 'Operator created'; $lang['stroperatorcreatedbad'] = 'Operator creation failed.'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index a23d90bc..5f75e2c0 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.67 2003/10/14 17:55:17 soranzo Exp $ + * $Id: english.php,v 1.68 2003/10/26 10:59:17 chriskl Exp $ */ // Language and character set @@ -110,6 +110,7 @@ $lang['strdownload'] = 'Download'; $lang['strinfo'] = 'Info'; $lang['stroids'] = 'OIDs'; + $lang['stradvanced'] = 'Advanced'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; @@ -488,9 +489,18 @@ $lang['strnooperator'] = 'No operator found.'; $lang['strnooperators'] = 'No operators found.'; $lang['strcreateoperator'] = 'Create operator'; - $lang['stroperatorname'] = 'Operator name'; $lang['strleftarg'] = 'Left Arg Type'; $lang['strrightarg'] = 'Right Arg Type'; + $lang['strcommutator'] = 'Commutator'; + $lang['strnegator'] = 'Negator'; + $lang['strrestrict'] = 'Restrict'; + $lang['strjoin'] = 'Join'; + $lang['strhashes'] = 'Hashes'; + $lang['strmerges'] = 'Merges'; + $lang['strleftsort'] = 'Left sort'; + $lang['strrightsort'] = 'Right sort'; + $lang['strlessthan'] = 'Less than'; + $lang['strgreaterthan'] = 'Greater than'; $lang['stroperatorneedsname'] = 'You must give a name for your operator.'; $lang['stroperatorcreated'] = 'Operator created'; $lang['stroperatorcreatedbad'] = 'Operator creation failed.'; diff --git a/operators.php b/operators.php index b72b9cc4..0a9ae28e 100644 --- a/operators.php +++ b/operators.php @@ -3,7 +3,7 @@ /** * Manage operators in a database * - * $Id: operators.php,v 1.6 2003/08/27 02:30:12 chriskl Exp $ + * $Id: operators.php,v 1.7 2003/10/26 10:59:16 chriskl Exp $ */ // Include application functions @@ -13,6 +13,90 @@ if (!isset($msg)) $msg = ''; $PHP_SELF = $_SERVER['PHP_SELF']; + /** + * Show read only properties for an operator + */ + function doProperties($msg = '') { + global $data, $localData, $misc; + global $PHP_SELF, $lang; + + echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['stroperators']}: ", $misc->printVal($_REQUEST['operator']), ": {$lang['strproperties']}

\n"; + $misc->printMsg($msg); + + $oprdata = &$localData->getOperator($_REQUEST['operator_oid']); + $oprdata->f['oprcanhash'] = $localData->phpBool($oprdata->f['oprcanhash']); + + if ($oprdata->recordCount() > 0) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
{$lang['strname']}", $misc->printVal($oprdata->f['oprname']), "
{$lang['strleftarg']}", $misc->printVal($oprdata->f['oprleftname']), "
{$lang['strrightarg']}", $misc->printVal($oprdata->f['oprrightname']), "
{$lang['strcommutator']}", $misc->printVal($oprdata->f['oprcom']), "
{$lang['strnegator']}", $misc->printVal($oprdata->f['oprnegate']), "
{$lang['strjoin']}", $misc->printVal($oprdata->f['oprjoin']), "
{$lang['strhashes']}", ($oprdata->f['oprcanhash']) ? $lang['stryes'] : $lang['strno'], "
{$lang['strmerges']}", ($oprdata->f['oprlsortop'] !== '0' && $oprdata->f['oprrsortop'] !== '0') ? $lang['stryes'] : $lang['strno'], "
{$lang['strrestrict']}", $misc->printVal($oprdata->f['oprrest']), "
{$lang['strleftsort']}", $misc->printVal($oprdata->f['oprlsortop']), "
{$lang['strrightsort']}", $misc->printVal($oprdata->f['oprrsortop']), "
{$lang['strlessthan']}", $misc->printVal($oprdata->f['oprltcmpop']), "
{$lang['strgreaterthan']}", $misc->printVal($oprdata->f['oprgtcmpop']), "
\n"; + + echo "

href}\">{$lang['strshowalloperators']}

\n"; + } + else + doDefault($lang['strinvalidparam']); + } + + /** + * Show confirmation of drop and perform actual drop + */ + function doDrop($confirm) { + global $localData, $database, $misc; + global $PHP_SELF, $lang; + + if ($confirm) { + echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['stroperators']}: ", $misc->printVal($_REQUEST['operator']), ": {$lang['strdrop']}

\n"; + + echo "

", sprintf($lang['strconfdropoperator'], $misc->printVal($_REQUEST['operator'])), "

\n"; + + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo $misc->form; + // Show cascade drop option if supportd + if ($localData->hasDropBehavior()) { + echo "

{$lang['strcascade']}

\n"; + } + echo "\n"; + echo "\n"; + echo "
\n"; + } + else { + $status = $localData->dropOperator($_POST['operator_oid'], isset($_POST['cascade'])); + if ($status == 0) + doDefault($lang['stroperatordropped']); + else + doDefault($lang['stroperatordroppedbad']); + } + + } + /** * Show default list of operators in the database */ @@ -29,7 +113,7 @@ echo "\n"; echo ""; echo ""; - //echo "\n"; + echo "\n"; echo "\n"; $i = 0; while (!$operators->EOF) { @@ -38,8 +122,10 @@ echo "\n"; echo "\n"; echo "\n"; - //echo "\n"; - //echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; $operators->moveNext(); $i++; @@ -50,7 +136,7 @@ echo "

{$lang['strnooperators']}

\n"; } - //echo "

href}\">{$lang['strcreateoperator']}

\n"; +// echo "

href}\">{$lang['strcreateoperator']}

\n"; } $misc->printHeader($lang['stroperators']); diff --git a/rules.php b/rules.php index 86b10b12..f6830e85 100644 --- a/rules.php +++ b/rules.php @@ -3,7 +3,7 @@ /** * List rules on a table * - * $Id: rules.php,v 1.14 2003/09/09 06:23:12 chriskl Exp $ + * $Id: rules.php,v 1.15 2003/10/26 10:59:16 chriskl Exp $ */ // Include application functions @@ -140,7 +140,7 @@ echo ""; echo "\n"; + "&table=", urlencode($_REQUEST['table']), "\">{$lang['strdrop']}\n"; $rules->movenext(); $i++; diff --git a/schema.php b/schema.php index 17619968..cf69b1d9 100755 --- a/schema.php +++ b/schema.php @@ -3,7 +3,7 @@ /** * Display properties of a schema * - * $Id: schema.php,v 1.7 2003/08/26 05:59:49 chriskl Exp $ + * $Id: schema.php,v 1.8 2003/10/26 10:59:16 chriskl Exp $ */ // Include application functions @@ -28,9 +28,12 @@ echo "
  • href}\">{$lang['strsequences']}
  • \n"; echo "
  • href}\">{$lang['strfunctions']}
  • \n"; echo "
  • href}\">{$lang['strdomains']}
  • \n"; + echo "
  • {$lang['stradvanced']}
  • \n"; + echo "\n"; + echo "\n"; } $misc->printHeader($lang['strschema'] . ' - ' . $_REQUEST['schema']); -- 2.39.5
    {$lang['stroperator']}{$lang['strleftarg']}{$lang['strrightarg']}{$lang['strreturns']}{$lang['stractions']}{$lang['stractions']}
    ", $misc->printVal($operators->f['oprleftname']), "", $misc->printVal($operators->f['oprrightname']), "", $misc->printVal($operators->f['resultname']), "href}&operatoroid=", urlencode($operators->f['oid']), "\">{$lang['strproperties']}href}&operatoroid=", urlencode($operators->f['oid']), "\">{$lang['strdrop']}href}&operator=", + urlencode($operators->f['oprname']), "&operator_oid=", urlencode($operators->f['oid']), "\">{$lang['strproperties']}href}&operator=", + urlencode($operators->f['oprname']), "&operator_oid=", urlencode($operators->f['oid']), "\">{$lang['strdrop']}
    ", $misc->printVal( $rules->f[$data->rlFields['ruledef']]), ""; echo "href}&rule=", urlencode($rules->f[$data->rlFields['rulename']]), - "&table=", urlencode($_REQUEST['table']), "\">{$lang['strdrop']}