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();
}