remove lots of duplicate funcs, more 7.1 fixes, lots of cleanups, support show_system...
authorchriskl <chriskl>
Thu, 15 May 2003 14:34:46 +0000 (14:34 +0000)
committerchriskl <chriskl>
Thu, 15 May 2003 14:34:46 +0000 (14:34 +0000)
classes/database/Postgres.php
classes/database/Postgres71.php
classes/database/Postgres72.php
classes/database/Postgres73.php

index e350d21820922064054568dc9af4a6ea9c65d670..abe1b70ca0f61d2e3cf4ba8898293c42a8840acd 100755 (executable)
@@ -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; }
 
 }
 
index 401ee90d93da77d7c9b76a48620f6fd5dc72e630..81c1d9f0ac0e42540badfa57d7b2591621e0e0cf 100644 (file)
@@ -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; }
index e328dd80768c6e8f4aa7c5ba003002562025062c..324a6bf4a3fcbcbba861c1855bbac6bc2981a0c6 100644 (file)
@@ -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.
index d0663c42149ef5f14a84ba06e2c09c2df0190719..b3b5482040cf78c7e7e3cfa0c11d01d1868f563f 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.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; }
 
 }