* 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???
$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')
function hasCreateTableLikeWithIndexes() {return false;}
function hasFTS() {return false;}
function hasVirtualTransactionId() {return false;}
+ function hasFunctionCosting() {return false;}
+ function hasFunctionGUC() {return false;}
}
?>
* 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 $
*/
* @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) {
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;
* 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???
* @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);
* 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');
* @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) {
}
// 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;
/**
* 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');
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;}
}
?>
/**
* 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
$_POST['original_arguments'],
&nbs