* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.122 2004/06/28 02:26:57 chriskl Exp $
+ * $Id: Postgres73.php,v 1.123 2004/07/06 09:05:42 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
* Creates a new schema.
* @param $schemaname The name of the schema to create
* @param $authorization (optional) The username to create the schema for.
- * @param $authorization (optional) If omitted, defaults to current user.
+ * @param $tablespace (optional) The tablespace for the schema, '' indicates default.
+ * @param $comment (optional) If omitted, defaults to nothing
* @return 0 success
*/
- function createSchema($schemaname, $authorization = '', $comment = '') {
+ function createSchema($schemaname, $authorization = '', $tablespace = '', $comment = '') {
$this->fieldClean($schemaname);
$this->fieldClean($authorization);
+ $this->fieldClean($tablespace);
$this->clean($comment);
$sql = "CREATE SCHEMA \"{$schemaname}\"";
if ($authorization != '') $sql .= " AUTHORIZATION \"{$authorization}\"";
-
+ if ($tablespace != '' && $this->hasTablespaces()) $sql .= " TABLESPACE \"{$tablespace}\"";
$status = $this->beginTransaction();
if ($status != 0) return -1;
$sql .= "{$returns} AS '\n";
$sql .= $definition;
$sql .= "\n'";
+
$sql .= " LANGUAGE \"{$language}\"";
// Add flags
/**
* PostgreSQL 7.5 support
*
- * $Id: Postgres75.php,v 1.7 2004/07/04 15:02:35 chriskl Exp $
+ * $Id: Postgres75.php,v 1.8 2004/07/06 09:05:42 chriskl Exp $
*/
include_once('./classes/database/Postgres74.php');
function Postgres75($conn) {
$this->Postgres74($conn);
}
+
+ // Schema functions
+
+ /**
+ * Return all schemas in the current database
+ * @return All schemas, sorted alphabetically
+ */
+ function &getSchemas() {
+ global $conf;
+
+ if (!$conf['show_system']) $and = "AND nspname NOT LIKE 'pg\\\\_%'";
+ else $and = '';
+ $sql = "SELECT pn.nspname, pu.usename AS nspowner, pg_catalog.obj_description(pn.oid, 'pg_namespace') AS comment,
+ (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pn.nsptablespace) AS tablespace
+ FROM pg_catalog.pg_namespace pn, pg_catalog.pg_user pu
+ WHERE pn.nspowner = pu.usesysid
+ {$and} ORDER BY nspname";
+
+ return $this->selectSet($sql);
+ }
/**
* Alters a column in a table
/**
* Manage schemas within a database
*
- * $Id: database.php,v 1.48 2004/06/11 05:08:19 xzilla Exp $
+ * $Id: database.php,v 1.49 2004/07/06 09:05:41 chriskl Exp $
*/
// Include application functions
if (!isset($_POST['formName'])) $_POST['formName'] = '';
if (!isset($_POST['formAuth'])) $_POST['formAuth'] = $_SESSION['webdbUsername'];
+ if (!isset($_POST['formSpc'])) $_POST['formSpc'] = '';
if (!isset($_POST['formComment'])) $_POST['formComment'] = '';
// Fetch all users from the database
$users = &$data->getUsers();
+ // Fetch all tablespaces from the database
+ if ($data->hasTablespaces()) $tablespaces = &$data->getTablespaces();
$misc->printTitle(array($misc->printVal($_REQUEST['database']),$lang['strcreateschema']),'create_schema');
$misc->printMsg($msg);
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n";
+ // Owner
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strowner']}</th>\n";
echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formAuth\">\n";
while (!$users->EOF) {
}
echo "\t\t\t</select>\n\t\t</td>\n\t\n";
+ // Tablespace (if there are any)
+ if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
+ echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n";
+ echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formSpc\">\n";
+ // Always offer the default (empty) option
+ echo "\t\t\t\t<option value=\"\"",
+ ($_POST['formSpc'] == '') ? ' selected="selected"' : '', "></option>\n";
+ // Display all other tablespaces
+ while (!$tablespaces->EOF) {
+ $spcname = htmlspecialchars($tablespaces->f['spcname']);
+ echo "\t\t\t\t<option value=\"{$spcname}\"",
+ ($spcname == $_POST['formSpc']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
+ $tablespaces->moveNext();
+ }
+ echo "\t\t\t</select>\n\t\t</td>\n\t\n";
+ }
+
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">",
htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
function doSaveCreate() {
global $data, $lang, $_reload_browser;
+ // Default tablespace to null if it isn't set
+ if (!isset($_POST['formSpc'])) $_POST['formSpc'] = null;
+
// Check that they've given a name
if ($_POST['formName'] == '') doCreate($lang['strschemaneedsname']);
else {
- $status = $data->createSchema($_POST['formName'], $_POST['formAuth'],$_POST['formComment']);
+ $status = $data->createSchema($_POST['formName'], $_POST['formAuth'], $_POST['formSpc'], $_POST['formComment']);
if ($status == 0) {
$_reload_browser = true;
doDefault($lang['strschemacreated']);
if ($schemas->recordCount() > 0) {
echo "<table>\n";
echo "<tr><th class=\"data\">{$lang['strname']}</th><th class=\"data\">{$lang['strowner']}</th>";
+ if ($data->hasTablespaces()) {
+ echo "<th class=\"data\">{$lang['strtablespace']}</th>";
+ }
echo "<th colspan=\"3\" class=\"data\">{$lang['stractions']}</th>";
if ($conf['show_comments']) echo "<th class=\"data\">{$lang['strcomment']}</th>\n";
echo "</tr>\n";
$id = (($i % 2) == 0 ? '1' : '2');
echo "<tr><td class=\"data{$id}\">", $misc->printVal($schemas->f[$data->nspFields['nspname']]), "</td>\n";
echo "<td class=\"data{$id}\">", $misc->printVal($schemas->f[$data->nspFields['nspowner']]), "</td>\n";
+ if ($data->hasTablespaces()) {
+ echo "<td class=\"data{$id}\">", $misc->printVal($schemas->f['tablespace']), "</td>\n";
+ }
echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop&database=",
urlencode($_REQUEST['database']), "&schema=",
urlencode($schemas->f[$data->nspFields['nspname']]), "\">{$lang['strdrop']}</a></td>\n";