add casts. some get parent tables stuff
authorchriskl <chriskl>
Sun, 26 Oct 2003 12:12:28 +0000 (12:12 +0000)
committerchriskl <chriskl>
Sun, 26 Oct 2003 12:12:28 +0000 (12:12 +0000)
BUGS
browser.php
casts.php [new file with mode: 0644]
classes/database/BaseDB.php
classes/database/Postgres73.php
lang/english.php
lang/recoded/english.php

diff --git a/BUGS b/BUGS
index 770737acd4450c24a16ca02722dd2d60c74c7821..9cce2a27717191e65ee13bc5d4fb52763d8556a8 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -1,6 +1,6 @@
+support for show_system in casts
 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 :(
 
-
index 8ec9605e13968402a90ee89e50d4153faf1069b0..527b93fad3ac1412fb67bb732f9199de0c5d72c4 100644 (file)
@@ -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.19 2003/10/26 10:59:16 chriskl Exp $
+        * $Id: browser.php,v 1.20 2003/10/26 12:12:28 chriskl Exp $
         */
 
        // Include application functions
                                
                                addNodes($db_node, $querystr);
                        }
+                       
+                       // Casts
+                       if ($data->hasCasts()) {                
+                               $cast_node = &new HTML_TreeNode(array(
+                                                               'text' => addslashes($lang['strcasts']), 
+                                                               'link' => addslashes(htmlspecialchars("casts.php?{$querystr}")), 
+                                                               'icon' => "../../../images/themes/{$conf['theme']}/types.png", 
+                                                               'expandedIcon' => "../../../images/themes/{$conf['theme']}/types.png",
+                                                               'expanded' => false,
+                                                               'linkTarget' => 'detail'));
 
+                               // Add folder to database
+                               $db_node->addItem($cast_node);
+                       }
+               
                        // Add node to menu
                        $root->addItem($db_node);
 
diff --git a/casts.php b/casts.php
new file mode 100644 (file)
index 0000000..061b272
--- /dev/null
+++ b/casts.php
@@ -0,0 +1,81 @@
+<?php
+
+       /**
+        * Manage casts in a database
+        *
+        * $Id: casts.php,v 1.1 2003/10/26 12:12:28 chriskl Exp $
+        */
+
+       // Include application functions
+       include_once('libraries/lib.inc.php');
+       
+       $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
+       if (!isset($msg)) $msg = '';
+       $PHP_SELF = $_SERVER['PHP_SELF'];
+
+       /**
+        * Show default list of casts in the database
+        */
+       function doDefault($msg = '') {
+               global $data, $localData, $misc, $database;
+               global $PHP_SELF, $lang;
+
+               echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strcasts']}</h2>\n";
+               $misc->printMsg($msg);
+               
+               $casts = &$localData->getcasts();
+
+               if ($casts->recordCount() > 0) {
+                       echo "<table>\n";
+                       echo "<tr><th class=\"data\">{$lang['strsourcetype']}</th><th class=\"data\">{$lang['strtargettype']}</th>";
+                       echo "<th class=\"data\">{$lang['strfunction']}</th><th class=\"data\">{$lang['strimplicit']}</th>";
+                       echo "</tr>\n";
+                       $i = 0;
+                       while (!$casts->EOF) {
+                               $id = (($i % 2) == 0 ? '1' : '2');
+                               echo "<tr><td class=\"data{$id}\">", $misc->printVal($casts->f['castsource']), "</td>\n";
+                               echo "<td class=\"data{$id}\">", $misc->printVal($casts->f['casttarget']), "</td>\n";
+                               echo "<td class=\"data{$id}\">", $misc->printVal($casts->f['castfunc']), "</td>\n";
+                               echo "<td class=\"data{$id}\">", $misc->printVal($casts->f['castcontext']), "</td>\n";
+                               echo "</tr>\n";
+                               $casts->moveNext();
+                               $i++;
+                       }
+                       echo "</table>\n";
+               }
+               else {
+                       echo "<p>{$lang['strnocasts']}</p>\n";
+               }
+               
+//             echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&amp;{$misc->href}\">{$lang['strcreatecast']}</a></p>\n";
+       }
+
+       $misc->printHeader($lang['strcasts']);
+       $misc->printBody();
+
+       switch ($action) {
+               case 'save_create':
+                       if (isset($_POST['cancel'])) doDefault();
+                       else doSaveCreate();
+                       break;
+               case 'create':
+                       doCreate();
+                       break;
+               case 'drop':
+                       if (isset($_POST['cancel'])) doDefault();
+                       else doDrop(false);
+                       break;
+               case 'confirm_drop':
+                       doDrop(true);
+                       break;                  
+               case 'properties':
+                       doProperties();
+                       break;
+               default:
+                       doDefault();
+                       break;
+       }       
+
+       $misc->printFooter();
+
+?>
index f679bfb6053b211a33364823d0cc2c74863f81dd..b78a6034a4dfb1eb74cae22aba165f9695815f5e 100644 (file)
@@ -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.31 2003/10/12 05:46:32 chriskl Exp $
+ * $Id: BaseDB.php,v 1.32 2003/10/26 12:12:28 chriskl Exp $
  */
 
 include_once('classes/database/ADODB_base.php');
@@ -231,7 +231,7 @@ class BaseDB extends ADODB_base {
        function hasRules() { return false; }
        function hasLanguages() { return false; }
        function hasSchemas() { return false; }
-       function hasConversions() { return false; }
+       function hasConversions() { return false; }     
        function hasGrantOption() { return false; }
        function hasCluster() { return false; }
        function hasDropBehavior() { return false; }
@@ -242,6 +242,7 @@ class BaseDB extends ADODB_base {
        function hasWithoutOIDs() { return false; }
        function hasAlterTableOwner() { return false; }
        function hasPartialIndexes() { return false; }
+       function hasCasts() { return false; }
 
 }
 
index 5f91c6b66ea5b0f8ea19ea78f21f633018b49616..fee1bf1fbc0499eddccc99d000edb462a819fb5c 100644 (file)
@@ -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.72 2003/10/26 10:59:16 chriskl Exp $
+ * $Id: Postgres73.php,v 1.73 2003/10/26 12:12:28 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -288,15 +288,15 @@ class Postgres73 extends Postgres72 {
                $this->clean($table);
                
                $sql = "                
-                       SELECT\r
-                         c.relname AS tablename,\r
-                         u.usename AS tableowner,\r
-                         pg_catalog.obj_description(c.oid, 'pg_class') AS tablecomment\r
-                       FROM pg_catalog.pg_class c\r
-                            LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner\r
-                            LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\r
-                       WHERE c.relkind = 'r'\r
-                             AND n.nspname = '{$this->_schema}'\r
+                       SELECT
+                         c.relname AS tablename,
+                         u.usename AS tableowner,
+                         pg_catalog.obj_description(c.oid, 'pg_class') AS tablecomment
+                       FROM pg_catalog.pg_class c
+                            LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
+                            LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+                       WHERE c.relkind = 'r'
+                             AND n.nspname = '{$this->_schema}'
                              AND c.relname = '{$table}'";              
                        
                return $this->selectSet($sql);
@@ -420,55 +420,55 @@ class Postgres73 extends Postgres72 {
                return $this->execute($sql);
        }
 
-       // Inheritance functions\r
-       \r
-       /**\r
-        * Finds the names and schemas of parent tables (in order)\r
-        * @param $table The table to find the parents for\r
-        * @return A recordset\r
-        */\r
-       function &getTableParents($table) {\r
-               $this->clean($table);\r
-               \r
-               $sql = "\r
-                       SELECT \r
-                               pn.nspname AS schemaname, relname\r
-                       FROM\r
-                               pg_catalog.pg_class pc, pg_catalog.pg_inherits pi, pg_catalog.pg_namespace pn\r
-                       WHERE\r
+       // Inheritance functions
+       
+       /**
+        * Finds the names and schemas of parent tables (in order)
+        * @param $table The table to find the parents for
+        * @return A recordset
+        */
+       function &getTableParents($table) {
+               $this->clean($table);
+               
+               $sql = "
+                       SELECT 
+                               pn.nspname AS schemaname, relname
+                       FROM
+                               pg_catalog.pg_class pc, pg_catalog.pg_inherits pi, pg_catalog.pg_namespace pn
+                       WHERE
                                pc.oid=pi.inhparent
-                               AND pc.relnamespace=pn.oid\r
+                               AND pc.relnamespace=pn.oid
                                AND pi.inhrelid = (SELECT oid from pg_catalog.pg_class WHERE relname='{$table}'
-                                       AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = '{$this->_schema}'))\r
-                       ORDER BY\r
-                               pi.inhseqno\r
-               ";\r
-               \r
-               return $this->selectSet($sql);                                  \r
-       }       \r
-\r
-\r
-       /**\r
-        * Finds the names and schemas of child tables\r
-        * @param $table The table to find the children for\r
-        * @return A recordset\r
-        */\r
-       function &getTableChildren($table) {\r
-               $this->clean($table);\r
-               \r
-               $sql = "\r
-                       SELECT \r
-                               pn.nspname AS schemaname, relname\r
-                       FROM\r
-                               pg_catalog.pg_class pc, pg_catalog.pg_inherits pi, pg_catalog.pg_namespace pn\r
-                       WHERE\r
+                                       AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = '{$this->_schema}'))
+                       ORDER BY
+                               pi.inhseqno
+               ";
+               
+               return $this->selectSet($sql);                                  
+       }       
+
+
+       /**
+        * Finds the names and schemas of child tables
+        * @param $table The table to find the children for
+        * @return A recordset
+        */
+       function &getTableChildren($table) {
+               $this->clean($table);
+               
+               $sql = "
+                       SELECT 
+                               pn.nspname AS schemaname, relname
+                       FROM
+                               pg_catalog.pg_class pc, pg_catalog.pg_inherits pi, pg_catalog.pg_namespace pn
+                       WHERE
                                pc.oid=pi.inhrelid
-                               AND pc.relnamespace=pn.oid\r
+                               AND pc.relnamespace=pn.oid
                                AND pi.inhparent = (SELECT oid from pg_catalog.pg_class WHERE relname='{$table}'
-                                       AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = '{$this->_schema}'))\r
-               ";\r
-               \r
-               return $this->selectSet($sql);                                  \r
+                                       AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = '{$this->_schema}'))
+               ";
+               
+               return $this->selectSet($sql);                                  
        }       
 
        // View functions
@@ -1263,6 +1263,33 @@ class Postgres73 extends Postgres72 {
        
                return $this->selectSet($sql);
        }
+
+       // Cast functions
+       
+       /**
+        * Returns a list of all casts in the database
+        * @return All casts
+        */      
+       function &getCasts() {
+       
+               $sql = "
+                       SELECT
+                               castsource::pg_catalog.regtype AS castsource,
+                               casttarget::pg_catalog.regtype AS casttarget,
+                               CASE WHEN castfunc = 0 THEN '(binary compatible)'
+                               ELSE p.proname
+                               END AS castfunc,
+                               CASE WHEN c.castcontext = 'e' THEN 'no'
+                               WHEN c.castcontext = 'a' THEN 'in assignment'
+                               ELSE 'yes'
+                               END AS castcontext
+                       FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p
+                               ON c.castfunc = p.oid
+                       ORDER BY 1, 2
+               ";
+
+               return $this->selectSet($sql);
+       }       
                
        // Capabilities
        function hasSchemas() { return true; }
@@ -1272,6 +1299,7 @@ class Postgres73 extends Postgres72 {
        function hasDropColumn() { return true; }
        function hasDomains() { return true; }
        function hasAlterTrigger() { return true; }
+       function hasCasts() { return true; }
 
 }
 
index 3cdaea75a4b4e7595016eb000680603b626194b5..d683230438036e76a6f69cb12ad897b68460b89b 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.116 2003/10/26 10:59:16 chriskl Exp $
+        * $Id: english.php,v 1.117 2003/10/26 12:12:28 chriskl Exp $
         */
 
        // Language and character set
        $lang['stroperatordropped'] = 'Operator dropped.';
        $lang['stroperatordroppedbad'] = 'Operator drop failed.';
 
+       // Casts
+       $lang['strcasts'] = 'Casts';
+       $lang['strnocasts'] = 'No casts found.';
+       $lang['strsourcetype'] = 'Source type';
+       $lang['strtargettype'] = 'Target type';
+       $lang['strimplicit'] = 'Implicit';
+       
        // Info
        $lang['strnoinfo'] = 'No information available.';
        $lang['strreferringtables'] = 'Referring tables';
index 5f75e2c0a3359cb4378004518e88ee798150f820..ec63f3976a488bdb6e6e9f8d9af2e3f01b513f8f 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.68 2003/10/26 10:59:17 chriskl Exp $
+        * $Id: english.php,v 1.69 2003/10/26 12:12:29 chriskl Exp $
         */
 
        // Language and character set
        $lang['stroperatordropped'] = 'Operator dropped.';
        $lang['stroperatordroppedbad'] = 'Operator drop failed.';
 
+       // Casts
+       $lang['strcasts'] = 'Casts';
+       $lang['strnocasts'] = 'No casts found.';
+       $lang['strsourcetype'] = 'Source type';
+       $lang['strtargettype'] = 'Target type';
+       $lang['strimplicit'] = 'Implicit';
+       
        // Info
        $lang['strnoinfo'] = 'No information available.';
        $lang['strreferringtables'] = 'Referring tables';