📄 pgsql.php
字号:
* 'name' => 'userlist', * 'add' => array( * 'quota' => array( * 'type' => 'integer', * 'unsigned' => 1 * ) * ), * 'remove' => array( * 'file_limit' => array(), * 'time_limit' => array() * ), * 'change' => array( * 'name' => array( * 'length' => '20', * 'definition' => array( * 'type' => 'text', * 'length' => 20, * ), * ) * ), * 'rename' => array( * 'sex' => array( * 'name' => 'gender', * 'definition' => array( * 'type' => 'text', * 'length' => 1, * 'default' => 'M', * ), * ) * ) * ) * * @param boolean $check indicates whether the function should just check if the DBMS driver * can perform the requested table alterations if the value is true or * actually perform them otherwise. * @access public * * @return mixed MDB2_OK on success, a MDB2 error on failure */ function alterTable($name, $changes, $check) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } foreach ($changes as $change_name => $change) { switch ($change_name) { case 'add': case 'remove': case 'change': case 'name': case 'rename': break; default: return $db->raiseError(MDB2_ERROR_CANNOT_ALTER, null, null, 'change type "'.$change_name.'\" not yet supported', __FUNCTION__); } } if ($check) { return MDB2_OK; } if (!empty($changes['remove']) && is_array($changes['remove'])) { foreach ($changes['remove'] as $field_name => $field) { $field_name = $db->quoteIdentifier($field_name, true); $query = 'DROP ' . $field_name; $result = $db->exec("ALTER TABLE $name $query"); if (PEAR::isError($result)) { return $result; } } } if (!empty($changes['rename']) && is_array($changes['rename'])) { foreach ($changes['rename'] as $field_name => $field) { $field_name = $db->quoteIdentifier($field_name, true); $result = $db->exec("ALTER TABLE $name RENAME COLUMN $field_name TO ".$db->quoteIdentifier($field['name'], true)); if (PEAR::isError($result)) { return $result; } } } if (!empty($changes['add']) && is_array($changes['add'])) { foreach ($changes['add'] as $field_name => $field) { $query = 'ADD ' . $db->getDeclaration($field['type'], $field_name, $field); $result = $db->exec("ALTER TABLE $name $query"); if (PEAR::isError($result)) { return $result; } } } if (!empty($changes['change']) && is_array($changes['change'])) { foreach ($changes['change'] as $field_name => $field) { $field_name = $db->quoteIdentifier($field_name, true); if (!empty($field['definition']['type'])) { $server_info = $db->getServerVersion(); if (PEAR::isError($server_info)) { return $server_info; } if (is_array($server_info) && $server_info['major'] < 8) { return $db->raiseError(MDB2_ERROR_CANNOT_ALTER, null, null, 'changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above', __FUNCTION__); } $db->loadModule('Datatype', null, true); $query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']); $result = $db->exec("ALTER TABLE $name $query"); if (PEAR::isError($result)) { return $result; } } if (array_key_exists('default', $field['definition'])) { $query = "ALTER $field_name SET DEFAULT ".$db->quote($field['definition']['default'], $field['definition']['type']); $result = $db->exec("ALTER TABLE $name $query"); if (PEAR::isError($result)) { return $result; } } if (!empty($field['definition']['notnull'])) { $query = "ALTER $field_name ".($field['definition']['notnull'] ? 'SET' : 'DROP').' NOT NULL'; $result = $db->exec("ALTER TABLE $name $query"); if (PEAR::isError($result)) { return $result; } } } } $name = $db->quoteIdentifier($name, true); if (!empty($changes['name'])) { $change_name = $db->quoteIdentifier($changes['name'], true); $result = $db->exec("ALTER TABLE $name RENAME TO ".$change_name); if (PEAR::isError($result)) { return $result; } } return MDB2_OK; } // }}} // {{{ listDatabases() /** * list all databases * * @return mixed array of database names on success, a MDB2 error on failure * @access public */ function listDatabases() { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $query = 'SELECT datname FROM pg_database'; $result2 = $db->standaloneQuery($query, array('text'), false); if (!MDB2::isResultCommon($result2)) { return $result2; } $result = $result2->fetchCol(); $result2->free(); 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; } // }}} // {{{ listUsers() /** * list all users * * @return mixed array of user names on success, a MDB2 error on failure * @access public */ function listUsers() { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $query = 'SELECT usename FROM pg_user'; $result2 = $db->standaloneQuery($query, array('text'), false); if (!MDB2::isResultCommon($result2)) { return $result2; } $result = $result2->fetchCol(); $result2->free(); return $result; } // }}} // {{{ listViews() /** * list all views in the current database * * @return mixed array of view names on success, a MDB2 error on failure * @access public */ function listViews() { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $query = "SELECT viewname FROM pg_views WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND viewname !~ '^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; } // }}} // {{{ listTableViews() /** * list the views in the database that reference a given table * * @param string table for which all referenced views should be found * @return mixed array of view names on success, a MDB2 error on failure * @access public */ function listTableViews($table) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $query = 'SELECT viewname FROM pg_views NATURAL JOIN pg_tables'; $query.= ' WHERE tablename ='.$db->quote($table, 'text'); $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; } // }}} // {{{ listFunctions() /** * list all functions in the current database * * @return mixed array of function names on success, a MDB2 error on failure * @access public */ function listFunctions() { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } $query = " SELECT proname FROM pg_proc pr, pg_type tp WHERE tp.oid = pr.prorettype AND pr.proisagg = FALSE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -