Skip to content

Commit

Permalink
Improve support for handling IN / named params in functions
Browse files Browse the repository at this point in the history
Based on work by Bert Thomas <bthomas@brothom.nl>
  • Loading branch information
xzilla committed Mar 2, 2014
1 parent 3e1604e commit 738651a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
9 changes: 7 additions & 2 deletions classes/database/Postgres.php
Expand Up @@ -4112,14 +4112,19 @@ function getFunction($function_oid) {

$sql = "
SELECT
pc.oid AS prooid, proname, pg_catalog.pg_get_userbyid(proowner) AS proowner,
pc.oid AS prooid, proname,
pg_catalog.pg_get_userbyid(proowner) AS proowner,
nspname as proschema, 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
proconfig,
(select array_agg( (select typname from pg_type pt
where pt.oid = p.oid) ) from unnest(proallargtypes) p)
AS proallarguments,
proargmodes
FROM
pg_catalog.pg_proc pc, pg_catalog.pg_language pl,
pg_catalog.pg_namespace pn
Expand Down
33 changes: 33 additions & 0 deletions classes/database/Postgres83.php
Expand Up @@ -322,6 +322,39 @@ function alterSequenceOwner($seqrs, $owner) {
return 0;
}

// Function functions

/**
* 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, pg_catalog.pg_get_userbyid(proowner) AS proowner,
nspname as proschema, 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,
pg_catalog.pg_namespace pn
WHERE
pc.oid = '{$function_oid}'::oid AND pc.prolang = pl.oid
AND pc.pronamespace = pn.oid
";

return $this->selectSet($sql);
}


// Capabilities
function hasQueryKill() { return false; }
function hasDatabaseCollation() { return false; }
function hasAlterSequenceStart() { return false; }
Expand Down
32 changes: 30 additions & 2 deletions functions.php
Expand Up @@ -83,12 +83,26 @@ function doEdit($msg = '') {

// Deal with named parameters
if ($data->hasNamedParams()) {
$args_arr = explode(', ', $fndata->fields['proarguments']);
if ( isset($fndata->fields['proallarguments']) ) {
$args_arr = $data->phpArray($fndata->fields['proallarguments']);
} else {
$args_arr = explode(', ', $fndata->fields['proarguments']);
}
$names_arr = $data->phpArray($fndata->fields['proargnames']);
$modes_arr = $data->phpArray($fndata->fields['proargmodes']);
$args = '';
$i = 0;
for ($i = 0; $i < sizeof($args_arr); $i++) {
if ($i != 0) $args .= ', ';
if (isset($modes_arr[$i])) {
switch($modes_arr[$i]) {
case 'i' : $args .= " IN "; break;
case 'o' : $args .= " OUT "; break;
case 'b' : $args .= " INOUT "; break;
case 'v' : $args .= " VARIADIC "; break;
case 't' : $args .= " TABLE "; break;
}
}
if (isset($names_arr[$i]) && $names_arr[$i] != '') {
$data->fieldClean($names_arr[$i]);
$args .= '"' . $names_arr[$i] . '" ';
Expand Down Expand Up @@ -241,12 +255,26 @@ function doProperties($msg = '') {
if ($funcdata->recordCount() > 0) {
// Deal with named parameters
if ($data->hasNamedParams()) {
$args_arr = explode(', ', $funcdata->fields['proarguments']);
if ( isset($funcdata->fields['proallarguments']) ) {
$args_arr = $data->phpArray($funcdata->fields['proallarguments']);
} else {
$args_arr = explode(', ', $funcdata->fields['proarguments']);
}
$names_arr = $data->phpArray($funcdata->fields['proargnames']);
$modes_arr = $data->phpArray($funcdata->fields['proargmodes']);
$args = '';
$i = 0;
for ($i = 0; $i < sizeof($args_arr); $i++) {
if ($i != 0) $args .= ', ';
if (isset($modes_arr[$i])) {
switch($modes_arr[$i]) {
case 'i' : $args .= " IN "; break;
case 'o' : $args .= " OUT "; break;
case 'b' : $args .= " INOUT "; break;
case 'v' : $args .= " VARIADIC "; break;
case 't' : $args .= " TABLE "; break;
}
}
if (isset($names_arr[$i]) && $names_arr[$i] != '') {
$data->fieldClean($names_arr[$i]);
$args .= '"' . $names_arr[$i] . '" ';
Expand Down

0 comments on commit 738651a

Please sign in to comment.