From 1315539424698699a681e931f0f65bb1d80f82d7 Mon Sep 17 00:00:00 2001 From: chriskl Date: Tue, 6 Jul 2004 09:05:41 +0000 Subject: [PATCH] support for schemas in tablespaces --- HISTORY | 1 + classes/database/Postgres73.php | 11 +++++++---- classes/database/Postgres75.php | 22 ++++++++++++++++++++- database.php | 34 +++++++++++++++++++++++++++++++-- lang/english.php | 3 ++- lang/recoded/english.php | 3 ++- 6 files changed, 65 insertions(+), 9 deletions(-) diff --git a/HISTORY b/HISTORY index b961099f..09b7c218 100644 --- a/HISTORY +++ b/HISTORY @@ -7,6 +7,7 @@ Version 3.5-dev Features * Context-sensitive online help system * Use language preferencies from browser (Markus Bertheau, Nicola Soranzo) +* Tablespace support for 7.5 Translations * Arabic from Zaki diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index 2694a4af..46881114 100644 --- a/classes/database/Postgres73.php +++ b/classes/database/Postgres73.php @@ -4,7 +4,7 @@ * 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??? @@ -128,17 +128,19 @@ class Postgres73 extends Postgres72 { * 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; @@ -827,6 +829,7 @@ class Postgres73 extends Postgres72 { $sql .= "{$returns} AS '\n"; $sql .= $definition; $sql .= "\n'"; + $sql .= " LANGUAGE \"{$language}\""; // Add flags diff --git a/classes/database/Postgres75.php b/classes/database/Postgres75.php index 654d0208..f80bbf06 100755 --- a/classes/database/Postgres75.php +++ b/classes/database/Postgres75.php @@ -3,7 +3,7 @@ /** * 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'); @@ -23,6 +23,26 @@ class Postgres75 extends Postgres74 { 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 diff --git a/database.php b/database.php index d7efef75..4561c088 100755 --- a/database.php +++ b/database.php @@ -3,7 +3,7 @@ /** * 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 @@ -524,10 +524,13 @@ 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); @@ -537,6 +540,7 @@ echo "\t\n\t\t{$lang['strname']}\n"; echo "\t\t_maxNameLen}\" value=\"", htmlspecialchars($_POST['formName']), "\" />\n\t\n"; + // Owner echo "\t\n\t\t{$lang['strowner']}\n"; echo "\t\t\n\t\t\t\n\t\t\n\t\n"; + // Tablespace (if there are any) + if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) { + echo "\t\n\t\t{$lang['strtablespace']}\n"; + echo "\t\t\n\t\t\t\n\t\t\n\t\n"; + } + echo "\t\n\t\t{$lang['strcomment']}\n"; echo "\t\t\n\t\n"; @@ -568,10 +589,13 @@ 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']); @@ -599,6 +623,9 @@ if ($schemas->recordCount() > 0) { echo "\n"; echo ""; + if ($data->hasTablespaces()) { + echo ""; + } echo ""; if ($conf['show_comments']) echo "\n"; echo "\n"; @@ -607,6 +634,9 @@ $id = (($i % 2) == 0 ? '1' : '2'); echo "\n"; echo "\n"; + if ($data->hasTablespaces()) { + echo "\n"; + } echo "\n"; diff --git a/lang/english.php b/lang/english.php index d52a2aa1..571f0d93 100755 --- a/lang/english.php +++ b/lang/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.149 2004/07/05 09:21:10 soranzo Exp $ + * $Id: english.php,v 1.150 2004/07/06 09:05:42 chriskl Exp $ */ // Language and character set @@ -596,6 +596,7 @@ // Tablespaces $lang['strtablespaces'] = 'Tablespaces'; + $lang['strtablespace'] = 'Tablespace'; $lang['strnotablespaces'] = 'No tablespaces found.'; $lang['strcreatetablespace'] = 'Create tablespace'; $lang['strlocation'] = 'Location'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index 25a28e9f..eb47cc41 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.102 2004/07/05 09:21:11 soranzo Exp $ + * $Id: english.php,v 1.103 2004/07/06 09:05:42 chriskl Exp $ */ // Language and character set @@ -596,6 +596,7 @@ // Tablespaces $lang['strtablespaces'] = 'Tablespaces'; + $lang['strtablespace'] = 'Tablespace'; $lang['strnotablespaces'] = 'No tablespaces found.'; $lang['strcreatetablespace'] = 'Create tablespace'; $lang['strlocation'] = 'Location'; -- 2.39.5
{$lang['strname']}{$lang['strowner']}{$lang['strtablespace']}{$lang['stractions']}{$lang['strcomment']}
", $misc->printVal($schemas->f[$data->nspFields['nspname']]), "", $misc->printVal($schemas->f[$data->nspFields['nspowner']]), "", $misc->printVal($schemas->f['tablespace']), "{$lang['strdrop']}