* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: BaseDB.php,v 1.15 2003/05/10 13:15:42 chriskl Exp $
+ * $Id: BaseDB.php,v 1.16 2003/05/11 15:13:29 chriskl Exp $
*/
include_once('classes/database/ADODB_base.php');
function hasGrantOption() { return false; }
function hasCluster() { return false; }
function hasDropBehavior() { return false; }
+ function hasSRFs() { return false; }
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.100 2003/05/11 10:39:29 chriskl Exp $
+ * $Id: Postgres.php,v 1.101 2003/05/11 15:13:30 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
'typout' => 'typout', 'typlen' => 'typlen', 'typdef' => 'typdef', 'typelem' => 'typelem',
'typdelim' => 'typdelim', 'typbyval' => 'typbyval',
'typalign' => 'typalign', 'typstorage' => 'typstorage');
+ var $fnFields = array('fnname' => 'proname', 'fnreturns' => 'return_type', 'fnarguments' => 'arguments','fnoid' => 'oid', 'fndef' => 'source', 'fnlang' => 'language', 'setof' => 'proretset' );
// Array of allowed type alignments
var $typAligns = array('char', 'int2', 'int4', 'double');
/**
* Updates a function. Postgres 7.1 doesn't have CREATE OR REPLACE function,
* so we do it with a drop and a recreate.
- * @param $funcname The name of the function to update
- * @param $definition The new definition for the function
+ * @param $funcname The name of the function to create
+ * @param $args The array of argument 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 returns a set, false otherwise
* @return 0 success
* @return -1 transaction error
* @return -2 drop function error
* @return -3 create function error
*/
- function setFunction($funcname, $definition) {
+ function setFunction($funcname, $args, $returns, $definition, $language, $flags, $setof) {
$status = $this->beginTransaction();
if ($status != 0) return -1;
- $status = $this->dropFunction($funcname);
+ $status = $this->dropFunction($funcname, false);
if ($status != 0) {
$this->rollbackTransaction();
return -2;
}
- $status = $this->createFunction($funcname, $definition);
+ $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, false);
if ($status != 0) {
$this->rollbackTransaction();
return -3;
* @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 $replace (optional) True if OR REPLACE, false for normal
* @return 0 success
*/
- function createFunction($funcname, $args, $returns, $definition, $language, $flags, $replace = false) {
+ function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $replace = false) {
+ if ($setof) return -99;
$this->fieldClean($funcname);
$this->clean($args);
$this->fieldClean($returns);
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres72.php,v 1.41 2003/05/07 15:00:56 chriskl Exp $
+ * $Id: Postgres72.php,v 1.42 2003/05/11 15:13:30 chriskl Exp $
*/
class Postgres72 extends Postgres71 {
- var $fnFields = array('fnname' => 'proname', 'fnreturns' => 'return_type', 'fnarguments' => 'arguments','fnoid' => 'oid', 'fndef' => 'source', 'fnlang' => 'language' );
var $langFields = array('lanname' => 'lanname');
var $privFields = array('privarr' => 'relacl');
$sql = "SELECT
p.oid,
p.proname,
+ false AS proretset,
format_type(p.prorettype, NULL) AS return_type,
oidvectortypes(p.proargtypes) AS arguments
FROM
* @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 returns a set, false otherwise
* @return 0 success
*/
- function setFunction($funcname, $args, $returns, $definition, $language, $flags) {
- return $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, true);
+ function setFunction($funcname, $args, $returns, $definition, $language, $flags, $setof) {
+ return $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, true);
}
// Type functions
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.42 2003/05/11 10:39:29 chriskl Exp $
+ * $Id: Postgres73.php,v 1.43 2003/05/11 15:13:31 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
{$distinct}
p.oid,
p.proname,
- CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||
- pg_catalog.format_type(p.prorettype, NULL) AS return_type,
+ p.proretset,
+ pg_catalog.format_type(p.prorettype, NULL) AS return_type,
pg_catalog.oidvectortypes(p.proargtypes) AS arguments
FROM pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
* @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 $replace (optional) True if OR REPLACE, false for normal
* @return 0 success
*/
- function createFunction($funcname, $args, $returns, $definition, $language, $flags, $replace = false) {
+ function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $replace = false) {
$this->fieldClean($funcname);
$this->clean($args);
$this->fieldClean($returns);
$sql .= $args;
// For some reason, the returns field cannot have quotes...
- $sql .= ") RETURNS {$returns} AS '\n";
+ $sql .= ") RETURNS ";
+ if ($setof) $sql .= "SETOF ";
+ $sql .= "{$returns} AS '\n";
$sql .= $definition;
$sql .= "\n'";
$sql .= " LANGUAGE \"{$language}\"";
function hasCluster() { return true; }
function hasDropBehavior() { return true; }
function hasDropColumn() { return true; }
+ function hasSRFs() { return true; }
}
/**
* Manage functions in a database
*
- * $Id: functions.php,v 1.11 2003/05/11 10:39:29 chriskl Exp $
+ * $Id: functions.php,v 1.12 2003/05/11 15:13:29 chriskl Exp $
*/
// Include application functions
if ($funcdata->recordCount() > 0) {
$func_full = $funcdata->f[$data->fnFields['fnname']] . "(". $funcdata->f[$data->fnFields['fnarguments']] .")";
- echo "<table width=90%>\n";
- echo "<tr><th class=data>{$lang['strfunctions']}</th>\n";
- echo "<th class=data>{$lang['strarguments']}</th>\n";
- echo "<th class=data>{$lang['strreturns']}</th>\n";
- echo "<th class=data>{$lang['strlanguage']}</th></tr>\n";
- echo "<tr><td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnname']]), "</td>\n";
- echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnarguments']]), "</td>\n";
- echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnreturns']]), "</td>\n";
- echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnlang']]), "</td></tr>\n";
- echo "<tr><th class=data colspan=4>{$lang['strdefinition']}</th></tr>\n";
- echo "<tr><td class=data1 colspan=4>", nl2br(htmlspecialchars($funcdata->f[$data->fnFields['fndef']])), "</td></tr>\n";
+ echo "<table width=\"90%\">\n";
+ echo "<tr><th class=\"data\">{$lang['strfunctions']}</th>\n";
+ echo "<th class=\"data\">{$lang['strarguments']}</th>\n";
+ echo "<th class=\"data\">{$lang['strreturns']}</th>\n";
+ echo "<th class=\"data\">{$lang['strlanguage']}</th></tr>\n";
+ echo "<tr><td class=\"data1\">", htmlspecialchars($funcdata->f[$data->fnFields['fnname']]), "</td>\n";
+ echo "<td class=\"data1\">", htmlspecialchars($funcdata->f[$data->fnFields['fnarguments']]), "</td>\n";
+ echo "<td class=\"data1\">", htmlspecialchars($funcdata->f[$data->fnFields['fnreturns']]), "</td>\n";
+ echo "<td class=\"data1\">", htmlspecialchars($funcdata->f[$data->fnFields['fnlang']]), "</td></tr>\n";
+ echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strdefinition']}</th></tr>\n";
+ echo "<tr><td class=\"data1\" colspan=\"4\">", nl2br(htmlspecialchars($funcdata->f[$data->fnFields['fndef']])), "</td></tr>\n";
echo "</table>\n";
}
else echo "<p>{$lang['strnodata']}</p>\n";
if (!isset($_POST['formLanguage'])) $_POST['formLanguage'] = '';
if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = '';
if (!isset($_POST['formProperties'])) $_POST['formProperties'] = $data->defaultprops;
+ if (!isset($_POST['formSetOf'])) $_POST['formSetOf'] = '';
$types = &$localData->getTypes(true);
$langs = &$localData->getLanguages();
echo "<td class=\"data1\"><input name=\"formArguments\" style=\"width:100%;\" size=\"16\" value=\"",
htmlspecialchars($_POST['formArguments']), "\" /></td>\n";
- echo "<td class=\"data1\"><select name=\"formReturns\">\n";
+ echo "<td class=\"data1\">\n";
+ // If supports set-returning-functions, output setof option
+ if ($data->hasSRFs()) {
+ echo "<select name=\"formSetOf\">\n";
+ echo "<option value=\"\"", ($_POST['formSetOf'] == '') ? ' selected' : '', "></option>\n";
+ echo "<option value=\"SETOF\"", ($_POST['formSetOf'] == 'SETOF') ? ' selected' : '', ">SETOF</option>\n";
+ echo "</select>\n";
+ }
+ // Output return type list
+ echo "<select name=\"formReturns\">\n";
while (!$types->EOF) {
echo "<option value=\"", htmlspecialchars($types->f[$data->typFields['typname']]), "\"",
($types->f[$data->typFields['typname']] == $_POST['formReturns']) ? ' selected' : '', ">",
else {
$status = $localData->createFunction($_POST['formFunction'], $_POST['formArguments'] ,
$_POST['formReturns'] , $_POST['formDefinition'] , $_POST['formLanguage'],
- $_POST['formProperties'], false);
+ $_POST['formProperties'], $_POST['formSetOf'] == 'SETOF', false);
if ($status == 0)
doDefault($lang['strfunctioncreated']);
else
if ($funcs->recordCount() > 0) {
echo "<table>\n";
- echo "<tr><th class=data>{$lang['strfunctions']}</th><th class=data>{$lang['strreturns']}</th><th class=data>{$lang['strarguments']}</th><th colspan=\"4\" class=data>{$lang['stractions']}</th>\n";
+ echo "<tr><th class=\"data\">{$lang['strfunctions']}</th><th class=\"data\">{$lang['strreturns']}</th>\n";
+ echo "<th class=\"data\">{$lang['strarguments']}</th><th colspan=\"4\" class=\"data\">{$lang['stractions']}</th>\n";
$i = 0;
while (!$funcs->EOF) {
+ $funcs->f[$data->fnFields['setof']] = $data->phpBool($funcs->f[$data->fnFields['setof']]);
$func_full = $funcs->f[$data->fnFields['fnname']] . "(". $funcs->f[$data->fnFields['fnarguments']] .")";
$id = (($i % 2) == 0 ? '1' : '2');
- echo "<tr><td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnname']]), "</td>\n";
- echo "<td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnreturns']]), "</td>\n";
- echo "<td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnarguments']]), "</td>\n";
- echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=properties&{$misc->href}&function=",
+ echo "<tr><td class=\"data{$id}\">", htmlspecialchars($funcs->f[$data->fnFields['fnname']]), "</td>\n";
+ echo "<td class=\"data{$id}\">";
+ if ($funcs->f[$data->fnFields['setof']]) echo "setof ";
+ echo htmlspecialchars($funcs->f[$data->fnFields['fnreturns']]), "</td>\n";
+ echo "<td class=\"data{$id}\">", htmlspecialchars($funcs->f[$data->fnFields['fnarguments']]), "</td>\n";
+ echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=properties&{$misc->href}&function=",
urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">{$lang['strproperties']}</a></td>\n";
- echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=edit&{$misc->href}&function=",
+ echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=edit&{$misc->href}&function=",
urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">{$lang['stredit']}</a></td>\n";
- echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&function=",
+ echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&function=",
urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">{$lang['strdrop']}</a></td>\n";
- echo "<td class=opbutton{$id}><a href=\"privileges.php?{$misc->href}&function=",
+ echo "<td class=\"opbutton{$id}\"><a href=\"privileges.php?{$misc->href}&function=",
urlencode($func_full), "&object=",
$funcs->f[$data->fnFields['fnoid']], "&type=function\">{$lang['strprivileges']}</a></td>\n";
echo "</tr>\n";
echo "<p>{$lang['strnofunctions']}</p>\n";
}
- echo "<p><a class=navlink href=\"$PHP_SELF?action=create&{$misc->href}\">{$lang['strcreatefunction']}</a></p>\n";
+ echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}\">{$lang['strcreatefunction']}</a></p>\n";
}