Postgres::setFunction PHP Method

setFunction() public method

Updates (replaces) a function.
public setFunction ( $function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $funcown, $newown, $funcschema, $newschema, $cost, $rows, $comment ) : -7
$function_oid The OID of the function
$funcname The name of the function to create
$newname The new name for the function
$args The array of argument types
$returns The return type
$definition The definition for the new function
$language The language the function is written for
$flags An array of optional flags
$setof True if returns a set, false otherwise
$comment The comment on the function
return -7
    function setFunction($function_oid, $funcname, $newname, $args, $returns, $definition, $language, $flags, $setof, $funcown, $newown, $funcschema, $newschema, $cost, $rows, $comment)
    {
        // Begin a transaction
        $status = $this->beginTransaction();
        if ($status != 0) {
            $this->rollbackTransaction();
            return -1;
        }
        // Replace the existing function
        $status = $this->createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment, true);
        if ($status != 0) {
            $this->rollbackTransaction();
            return $status;
        }
        $f_schema = $this->_schema;
        $this->fieldClean($f_schema);
        // Rename the function, if necessary
        $this->fieldClean($newname);
        /* $funcname is escaped in createFunction */
        if ($funcname != $newname) {
            $sql = "ALTER FUNCTION \"{$f_schema}\".\"{$funcname}\"({$args}) RENAME TO \"{$newname}\"";
            $status = $this->execute($sql);
            if ($status != 0) {
                $this->rollbackTransaction();
                return -5;
            }
            $funcname = $newname;
        }
        // Alter the owner, if necessary
        if ($this->hasFunctionAlterOwner()) {
            $this->fieldClean($newown);
            if ($funcown != $newown) {
                $sql = "ALTER FUNCTION \"{$f_schema}\".\"{$funcname}\"({$args}) OWNER TO \"{$newown}\"";
                $status = $this->execute($sql);
                if ($status != 0) {
                    $this->rollbackTransaction();
                    return -6;
                }
            }
        }
        // Alter the schema, if necessary
        if ($this->hasFunctionAlterSchema()) {
            $this->fieldClean($newschema);
            /* $funcschema is escaped in createFunction */
            if ($funcschema != $newschema) {
                $sql = "ALTER FUNCTION \"{$f_schema}\".\"{$funcname}\"({$args}) SET SCHEMA \"{$newschema}\"";
                $status = $this->execute($sql);
                if ($status != 0) {
                    $this->rollbackTransaction();
                    return -7;
                }
            }
        }
        return $this->endTransaction();
    }
Postgres