⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgsql.php

📁 开源邮件管理系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:
                AND tp.typname <> 'trigger'                AND pr.pronamespace IN                    (SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";        $result = $db->queryCol($query);        if (PEAR::isError($result)) {            return $result;        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);        }        return $result;    }    // }}}    // {{{ listTableTriggers()    /**     * list all triggers in the database that reference a given table     *     * @param string table for which all referenced triggers should be found     * @return mixed array of trigger names on success, a MDB2 error on failure     * @access public     */    function listTableTriggers($table = null)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $query = 'SELECT trg.tgname AS trigger_name                    FROM pg_trigger trg,                         pg_class tbl                   WHERE trg.tgrelid = tbl.oid';        if (!is_null($table)) {            $table = $db->quote(strtoupper($table), 'text');            $query .= " AND tbl.relname = $table";        }        $result = $db->queryCol($query);        if (PEAR::isError($result)) {            return $result;        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);        }        return $result;    }    // }}}    // {{{ listTables()    /**     * list all tables in the current database     *     * @return mixed array of table names on success, a MDB2 error on failure     * @access public     */    function listTables()    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        // gratuitously stolen from PEAR DB _getSpecialQuery in pgsql.php        $query = 'SELECT c.relname AS "Name"'            . ' FROM pg_class c, pg_user u'            . ' WHERE c.relowner = u.usesysid'            . " AND c.relkind = 'r'"            . ' AND NOT EXISTS'            . ' (SELECT 1 FROM pg_views'            . '  WHERE viewname = c.relname)'            . " AND c.relname !~ '^(pg_|sql_)'"            . ' UNION'            . ' SELECT c.relname AS "Name"'            . ' FROM pg_class c'            . " WHERE c.relkind = 'r'"            . ' AND NOT EXISTS'            . ' (SELECT 1 FROM pg_views'            . '  WHERE viewname = c.relname)'            . ' AND NOT EXISTS'            . ' (SELECT 1 FROM pg_user'            . '  WHERE usesysid = c.relowner)'            . " AND c.relname !~ '^pg_'";        $result = $db->queryCol($query);        if (PEAR::isError($result)) {            return $result;        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);        }        return $result;    }    // }}}    // {{{ listTableFields()    /**     * list all fields in a table in the current database     *     * @param string $table name of table that should be used in method     * @return mixed array of field names on success, a MDB2 error on failure     * @access public     */    function listTableFields($table)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $table = $db->quoteIdentifier($table, true);        $db->setLimit(1);        $result2 = $db->query("SELECT * FROM $table");        if (PEAR::isError($result2)) {            return $result2;        }        $result = $result2->getColumnNames();        $result2->free();        if (PEAR::isError($result)) {            return $result;        }        return array_flip($result);    }    // }}}    // {{{ listTableIndexes()    /**     * list all indexes in a table     *     * @param string $table name of table that should be used in method     * @return mixed array of index names on success, a MDB2 error on failure     * @access public     */    function listTableIndexes($table)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $table = $db->quote($table, 'text');        $subquery = "SELECT indexrelid FROM pg_index, pg_class";        $subquery.= " WHERE pg_class.relname=$table AND pg_class.oid=pg_index.indrelid AND indisunique != 't' AND indisprimary != 't'";        $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";        $indexes = $db->queryCol($query, 'text');        if (PEAR::isError($indexes)) {            return $indexes;        }        $result = array();        foreach ($indexes as $index) {            $index = $this->_fixIndexName($index);            if (!empty($index)) {                $result[$index] = true;            }        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_change_key_case($result, $db->options['field_case']);        }        return array_keys($result);    }    // }}}    // {{{ listTableConstraints()    /**     * list all constraints in a table     *     * @param string $table name of table that should be used in method     * @return mixed array of constraint names on success, a MDB2 error on failure     * @access public     */    function listTableConstraints($table)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $table = $db->quote($table, 'text');        $query = 'SELECT conname                    FROM pg_constraint, pg_class                   WHERE pg_constraint.conrelid = pg_class.oid                     AND relname = ' .$table;        $constraints = $db->queryCol($query);        if (PEAR::isError($constraints)) {            return $constraints;        }        $result = array();        foreach ($constraints as $constraint) {            $constraint = $this->_fixIndexName($constraint);            if (!empty($constraint)) {                $result[$constraint] = true;            }        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE            && $db->options['field_case'] == CASE_LOWER        ) {            $result = array_change_key_case($result, $db->options['field_case']);        }        return array_keys($result);    }    // }}}    // {{{ createSequence()    /**     * create sequence     *     * @param string $seq_name name of the sequence to be created     * @param string $start start value of the sequence; default is 1     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function createSequence($seq_name, $start = 1)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);        return $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".            ($start < 1 ? " MINVALUE $start" : '')." START $start");    }    // }}}    // {{{ dropSequence()    /**     * drop existing sequence     *     * @param string $seq_name name of the sequence to be dropped     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function dropSequence($seq_name)    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);        return $db->exec("DROP SEQUENCE $sequence_name");    }    // }}}    // {{{ listSequences()    /**     * list all sequences in the current database     *     * @return mixed array of sequence names on success, a MDB2 error on failure     * @access public     */    function listSequences()    {        $db =& $this->getDBInstance();        if (PEAR::isError($db)) {            return $db;        }        $query = "SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN";        $query.= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";        $table_names = $db->queryCol($query);        if (PEAR::isError($table_names)) {            return $table_names;        }        $result = array();        foreach ($table_names as $table_name) {            $result[] = $this->_fixSequenceName($table_name);        }        if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $result = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $result);        }        return $result;    }}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -