add function costing var (costs & rows) new in 8.3
authorxzilla <xzilla>
Thu, 15 Nov 2007 06:06:45 +0000 (06:06 +0000)
committerxzilla <xzilla>
Thu, 15 Nov 2007 06:06:45 +0000 (06:06 +0000)
classes/database/Postgres.php
classes/database/Postgres72.php
classes/database/Postgres73.php
classes/database/Postgres74.php
classes/database/Postgres83.php
functions.php
lang/english.php
lang/recoded/english.php
lang/recoded/french.php

index 1fc3a0277a5b41094db6ab66aa1657b61e4cc400..8ad6dd7e5f9ac732422a66ef615b37e0d5c87ab2 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.308 2007/10/17 15:55:33 ioguix Exp $
+ * $Id: Postgres.php,v 1.309 2007/11/15 06:06:45 xzilla Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -644,7 +644,7 @@ class Postgres extends ADODB_base {
                $sql = "SELECT NULL AS nspname, c.relname,
                                        (SELECT usename FROM pg_user u WHERE u.usesysid=c.relowner) AS relowner,
                                        (SELECT description FROM pg_description pd WHERE c.oid=pd.objoid) AS relcomment,
-                                       reltuples::bigint AS reltuples
+                                       reltuples::bigint AS reltuples 
                                FROM pg_class c
                                WHERE c.relkind='r'
                                        AND NOT EXISTS (SELECT 1 FROM pg_rewrite r WHERE r.ev_class = c.oid AND r.ev_type = '1')
@@ -4844,6 +4844,8 @@ class Postgres extends ADODB_base {
        function hasCreateTableLikeWithIndexes() {return false;}
        function hasFTS() {return false;}
        function hasVirtualTransactionId() {return false;}
+       function hasFunctionCosting() {return false;}
+       function hasFunctionGUC() {return false;}
 }
 
 ?>
index 49ccd80760cd2fd4e4b24534d50b20e42e46e12e..eb33a06d555ebf50ac9fa237494f8876c3476325 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.91 2007/10/18 12:29:40 xzilla Exp $
+ * $Id: Postgres72.php,v 1.92 2007/11/15 06:06:45 xzilla Exp $
  */
 
 
@@ -441,7 +441,7 @@ class Postgres72 extends Postgres71 {
         * @return -3 create function error
         * @return -4 comment error
         */
-       function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $comment) {
+       function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $rows, $cost, $comment) {
                // Begin a transaction
                $status = $this->beginTransaction();
                if ($status != 0) {
@@ -457,13 +457,13 @@ class Postgres72 extends Postgres71 {
                                return -2;
                        }
 
-                       $status = $this->createFunction($newname, $args, $returns, $definition, $language, $flags, $setof, false);
+                       $status = $this->createFunction($newname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, false);
                        if ($status != 0) {
                                $this->rollbackTransaction();
                                return -3;
                        }
                } else {
-                       $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
+                       $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, true);
                        if ($status != 0) {
                                $this->rollbackTransaction();
                                return -3;
index 6bce5929d1e42b66c7872e58592e99dcd349fb92..4e52dec2e1d51ceee706daa1efa655f11f1eed37 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.174 2007/10/17 15:55:33 ioguix Exp $
+ * $Id: Postgres73.php,v 1.175 2007/11/15 06:06:45 xzilla Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -974,7 +974,7 @@ class Postgres73 extends Postgres72 {
         * @param $replace (optional) True if OR REPLACE, false for normal
         * @return 0 success
         */
-       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $replace = false) {
+       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $replace = false) {
                $this->fieldClean($funcname);
                $this->clean($args);
                $this->clean($language);
index 36820e766fcf667984bb1b3048eec4e4eecf8129..028080ec7dd1006a155cff963653ebd070b10b59 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres74.php,v 1.64 2007/10/17 15:55:33 ioguix Exp $
+ * $Id: Postgres74.php,v 1.65 2007/11/15 06:06:45 xzilla Exp $
  */
 
 include_once('./classes/database/Postgres73.php');
@@ -566,7 +566,7 @@ class Postgres74 extends Postgres73 {
         * @return -4 comment error
         * @return -5 rename function error
         */
-       function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $comment) {
+       function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment) {
                // Begin a transaction
                $status = $this->beginTransaction();
                if ($status != 0) {
@@ -575,7 +575,7 @@ class Postgres74 extends Postgres73 {
                }
 
                // Replace the existing function
-               $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
+               $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, true);
                if ($status != 0) {
                        $this->rollbackTransaction();
                        return -3;
index 8e3ebe4db0d26fed2f1d7a7b87b3c1c0fcda2b1d..5dd314277ef9f37c4d1ae45bc118af4750bdcb02 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * PostgreSQL 8.3 support
  *
- * $Id: Postgres83.php,v 1.10 2007/10/17 18:24:32 ioguix Exp $
+ * $Id: Postgres83.php,v 1.11 2007/11/15 06:06:45 xzilla Exp $
  */
 
 include_once('./classes/database/Postgres82.php');
@@ -696,10 +696,113 @@ class Postgres83 extends Postgres82 {
                return $this->selectSet($sql);
        }
 
+       /**
+        * Creates a new function.
+        * @param $funcname The name of the function to create
+        * @param $args A comma separated string of types
+        * @param $returns The return type
+        * @param $definition The definition for the new function
+        * @param $language The language the function is written for
+        * @param $flags An array of optional flags
+        * @param $setof True if it returns a set, false otherwise
+        * @param $rows number of rows planner should estimate will be returned
+     * @param $cost cost the planner should use in the function execution step 
+        * @param $replace (optional) True if OR REPLACE, false for normal
+        * @return 0 success
+        */
+       function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $replace = false) {
+               $this->fieldClean($funcname);
+               $this->clean($args);
+               $this->clean($language);
+               $this->arrayClean($flags);
+               $this->clean($cost);
+               $this->clean($rows);
+
+               $sql = "CREATE";
+               if ($replace) $sql .= " OR REPLACE";
+               $sql .= " FUNCTION \"{$funcname}\" (";
+               
+               if ($args != '')
+                       $sql .= $args;
+
+               // For some reason, the returns field cannot have quotes...
+               $sql .= ") RETURNS ";
+               if ($setof) $sql .= "SETOF ";
+               $sql .= "{$returns} AS ";
+               
+               if (is_array($definition)) {
+                       $this->arrayClean($definition);
+                       $sql .= "'" . $definition[0] . "'";
+                       if ($definition[1]) {
+                               $sql .= ",'" . $definition[1] . "'";
+                       }
+               } else {
+                       $this->clean($definition);
+                       $sql .= "'" . $definition . "'";
+               }
+               
+               $sql .= " LANGUAGE \"{$language}\"";
+
+               // Add costs
+               $sql .= " COST {$cost}";
+
+               if ($rows <> 0 ){
+                       $sql .= " ROWS {$rows}";
+               }
+               
+               // Add flags
+               foreach ($flags as  $v) {
+                       // Skip default flags
+                       if ($v == '') continue;
+                       else $sql .= "\n{$v}";
+               }
+
+               return $this->execute($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 AS prooid,
+                                       proname,
+                                       lanname as prolanguage,
+                                       procost,
+                                       prorows,
+                                       pg_catalog.format_type(prorettype, NULL) as proresult,
+                                       prosrc,
+                                       probin,
+                                       proretset,
+                                       proisstrict,
+                                       provolatile,
+                                       prosecdef,
+                                       pg_catalog.oidvectortypes(pc.proargtypes) AS proarguments,
+                                       proargnames AS proargnames,
+                                       pg_catalog.obj_description(pc.oid, 'pg_proc') AS procomment,
+                                       proconfig 
+                               FROM
+                                       pg_catalog.pg_proc pc, pg_catalog.pg_language pl
+                               WHERE 
+                                       pc.oid = '{$function_oid}'::oid
+                               AND pc.prolang = pl.oid
+                               ";
+       
+               return $this->selectSet($sql);
+       }
+       
+
+
        // Capabilities
        function hasCreateTableLikeWithIndexes() {return true;}
        function hasVirtualTransactionId() {return true;}
        function hasEnumTypes() {return true;}
        function hasFTS() {return true;}
+       function hasFunctionCosting() {return true;}
+       function hasFunctionGUC() {return true;}
 }
 ?>
index 3415612c398e726bee8991f2acb20e53427bc0b2..ab8145a095d559112b0bb3f3915f215e56a82d21 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage functions in a database
         *
-        * $Id: functions.php,v 1.69 2007/10/31 03:40:05 xzilla Exp $
+        * $Id: functions.php,v 1.70 2007/11/15 06:06:45 xzilla Exp $
         */
 
        // Include application functions
@@ -32,7 +32,8 @@
                                                                                $_POST['original_arguments'], 
                            &nbs