Postgres::createFunction PHP Метод

createFunction() публичный Метод

Creates a new function.
public createFunction ( $funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment, $replace = false ) : -4
$funcname The name of the function to create
$args A comma separated string of 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 it returns a set, false otherwise
$cost cost the planner should use in the function execution step
$rows number of rows planner should estimate will be returned
$comment Comment for the function
$replace (optional) True if OR REPLACE, false for normal
Результат -4
    function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment, $replace = false)
    {
        // Begin a transaction
        $status = $this->beginTransaction();
        if ($status != 0) {
            $this->rollbackTransaction();
            return -1;
        }
        $this->fieldClean($funcname);
        $this->clean($args);
        $this->fieldClean($language);
        $this->arrayClean($flags);
        $this->clean($cost);
        $this->clean($rows);
        $f_schema = $this->_schema;
        $this->fieldClean($f_schema);
        $sql = "CREATE";
        if ($replace) {
            $sql .= " OR REPLACE";
        }
        $sql .= " FUNCTION \"{$f_schema}\".\"{$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
        if (!empty($cost)) {
            $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}";
            }
        }
        $status = $this->execute($sql);
        if ($status != 0) {
            $this->rollbackTransaction();
            return -3;
        }
        /* set the comment */
        $status = $this->setComment('FUNCTION', "\"{$funcname}\"({$args})", null, $comment);
        if ($status != 0) {
            $this->rollbackTransaction();
            return -4;
        }
        return $this->endTransaction();
    }
Postgres