From eb465a65c6bed5b4fa661b7c99c6fb5e7a9b8ad4 Mon Sep 17 00:00:00 2001 From: "Guillaume (ioguix) de Rorthais" Date: Thu, 13 Aug 2009 22:29:19 -0400 Subject: [PATCH] add support for database level collation --- all_db.php | 30 +++++++++++++++++++++- classes/database/Postgres.php | 33 ++++++++++++++++-------- classes/database/Postgres83.php | 45 +++++++++++++++++++++++++++++++++ lang/english.php | 2 ++ lang/french.php | 7 +++++ lang/recoded/english.php | 2 ++ lang/recoded/french.php | 9 +++++++ 7 files changed, 116 insertions(+), 12 deletions(-) diff --git a/all_db.php b/all_db.php index 33131603..b2b515b3 100644 --- a/all_db.php +++ b/all_db.php @@ -199,6 +199,7 @@ echo "\t\t\t\n"; echo "\t\t\n\t\n"; + // ENCODING echo "\t\n\t\t{$lang['strencoding']}\n"; echo "\t\t\n"; echo "\t\t\t\n"; echo "\t\t\n\t\n"; + if ($data->hasDatabaseCollation()) { + if (!isset($_POST['formCollate'])) $_POST['formCollate'] = ''; + if (!isset($_POST['formCType'])) $_POST['formCType'] = ''; + + // LC_COLLATE + echo "\t\n\t\t{$lang['strcollation']}\n"; + echo "\t\t\n"; + echo "\t\t\t\n"; + echo "\t\t\n\t\n"; + + // LC_CTYPE + echo "\t\n\t\t{$lang['strctype']}\n"; + echo "\t\t\n"; + echo "\t\t\t\n"; + echo "\t\t\n\t\n"; + } + // Tablespace (if there are any) if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) { echo "\t\n\t\t{$lang['strtablespace']}\n"; @@ -258,7 +276,8 @@ // Check that they've given a name and a definition if ($_POST['formName'] == '') doCreate($lang['strdatabaseneedsname']); else { - $status = $data->createDatabase($_POST['formName'], $_POST['formEncoding'], $_POST['formSpc'], $_POST['formComment'], $_POST['formTemplate']); + $status = $data->createDatabase($_POST['formName'], $_POST['formEncoding'], $_POST['formSpc'], + $_POST['formComment'], $_POST['formTemplate'], $_POST['formCollate'], $_POST['formCType']); if ($status == 0) { $_reload_browser = true; doDefault($lang['strdatabasecreated']); @@ -345,6 +364,14 @@ 'title' => $lang['strencoding'], 'field' => field('datencoding'), ), + 'lc_collate' => array( + 'title' => $lang['strcollation'], + 'field' => field('datcollate'), + ), + 'lc_ctype' => array( + 'title' => $lang['strctype'], + 'field' => field('datctype'), + ), 'tablespace' => array( 'title' => $lang['strtablespace'], 'field' => field('tablespace'), @@ -391,6 +418,7 @@ if (!$data->hasTablespaces()) unset($columns['tablespace']); if (!$data->hasServerAdminFuncs()) unset($columns['dbsize']); + if (!$data->hasDatabaseCollation()) unset($columns['lc_collate'], $columns['lc_ctype']); if (!isset($data->privlist['database'])) unset($actions['privileges']); $misc->printTable($databases, $columns, $actions, $lang['strnodatabases']); diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index 9b4d0d17..6b20edb6 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -445,6 +445,8 @@ class Postgres extends ADODB_base { /** * Return all database available on the server + * @param $currentdatabase database name that should be on top of the resultset + * * @return A list of databases, sorted alphabetically */ function getDatabases($currentdatabase = NULL) { @@ -469,15 +471,17 @@ class Postgres extends ADODB_base { else $where = ' AND pdb.datallowconn'; - $sql = "SELECT pdb.datname AS datname, pr.rolname AS datowner, pg_encoding_to_char(encoding) AS datencoding, - (SELECT description FROM pg_catalog.pg_shdescription pd WHERE pdb.oid=pd.objoid) AS datcomment, - (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pdb.dattablespace) AS tablespace, - pg_catalog.pg_database_size(pdb.oid) as dbsize - FROM pg_catalog.pg_database pdb LEFT JOIN pg_catalog.pg_roles pr ON (pdb.datdba = pr.oid) - WHERE true - {$where} - {$clause} - {$orderby}"; + $sql = " + SELECT pdb.datname AS datname, pr.rolname AS datowner, pg_encoding_to_char(encoding) AS datencoding, + (SELECT description FROM pg_catalog.pg_shdescription pd WHERE pdb.oid=pd.objoid) AS datcomment, + (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pdb.dattablespace) AS tablespace, + pg_catalog.pg_database_size(pdb.oid) as dbsize, pdb.datcollate, pdb.datctype + FROM pg_catalog.pg_database pdb + LEFT JOIN pg_catalog.pg_roles pr ON (pdb.datdba = pr.oid) + WHERE true + {$where} + {$clause} + {$orderby}"; return $this->selectSet($sql); } @@ -545,22 +549,28 @@ class Postgres extends ADODB_base { * @return -1 tablespace error * @return -2 comment error */ - function createDatabase($database, $encoding, $tablespace = '', $comment = '', $template = 'template1') { + function createDatabase($database, $encoding, $tablespace = '', $comment = '', $template = 'template1', + $lc_collate = '', $lc_ctype = '') + { $this->fieldClean($database); $this->clean($encoding); $this->fieldClean($tablespace); - $this->fieldClean($comment); $this->fieldClean($template); + $this->clean($lc_collate); + $this->clean($lc_ctype); $sql = "CREATE DATABASE \"{$database}\" WITH TEMPLATE=\"{$template}\""; if ($encoding != '') $sql .= " ENCODING='{$encoding}'"; + if ($lc_collate != '') $sql .= " LC_COLLATE='{$lc_collate}'"; + if ($lc_ctype != '') $sql .= " LC_CTYPE='{$lc_ctype}'"; if ($tablespace != '' && $this->hasTablespaces()) $sql .= " TABLESPACE \"{$tablespace}\""; $status = $this->execute($sql); if ($status != 0) return -1; + $this->fieldClean($comment); if ($comment != '' && $this->hasSharedComments()) { $status = $this->setComment('DATABASE',$database,'',$comment); if ($status != 0) return -2; @@ -7575,6 +7585,7 @@ class Postgres extends ADODB_base { function hasVirtualTransactionId() { return true; } function hasWithoutOIDs() { return true; } function hasAlterDatabase() { return $this->hasAlterDatabaseRename(); } + function hasDatabaseCollation() { return true; } function hasMagicTypes() { return true; } function hasQueryKill() { return true; } function hasConcurrentIndexBuild() { return true; } diff --git a/classes/database/Postgres83.php b/classes/database/Postgres83.php index cc399dc5..7fcc2ee4 100644 --- a/classes/database/Postgres83.php +++ b/classes/database/Postgres83.php @@ -56,8 +56,53 @@ class Postgres83 extends Postgres { return $this->help_page; } + // Databse functions + + /** + * Return all database available on the server + * @param $currentdatabase database name that should be on top of the resultset + * + * @return A list of databases, sorted alphabetically + */ + function getDatabases($currentdatabase = NULL) { + global $conf, $misc; + + $server_info = $misc->getServerInfo(); + + if (isset($conf['owned_only']) && $conf['owned_only'] && !$this->isSuperUser($server_info['username'])) { + $username = $server_info['username']; + $this->clean($username); + $clause = " AND pr.rolname='{$username}'"; + } + else $clause = ''; + + if ($currentdatabase != NULL) + $orderby = "ORDER BY pdb.datname = '{$currentdatabase}' DESC, pdb.datname"; + else + $orderby = "ORDER BY pdb.datname"; + + if (!$conf['show_system']) + $where = ' AND NOT pdb.datistemplate'; + else + $where = ' AND pdb.datallowconn'; + + $sql = " + SELECT pdb.datname AS datname, pr.rolname AS datowner, pg_encoding_to_char(encoding) AS datencoding, + (SELECT description FROM pg_catalog.pg_shdescription pd WHERE pdb.oid=pd.objoid) AS datcomment, + (SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=pdb.dattablespace) AS tablespace, + pg_catalog.pg_database_size(pdb.oid) as dbsize + FROM pg_catalog.pg_database pdb LEFT JOIN pg_catalog.pg_roles pr ON (pdb.datdba = pr.oid) + WHERE true + {$where} + {$clause} + {$orderby}"; + + return $this->selectSet($sql); + } + function hasAutovacuumSysTable() { return true; } function hasQueryKill() { return false; } + function hasDatabaseCollation() { return false; } } diff --git a/lang/english.php b/lang/english.php index a0758597..66c67045 100644 --- a/lang/english.php +++ b/lang/english.php @@ -139,6 +139,8 @@ $lang['strselectall'] = 'Select all'; $lang['strunselectall'] = 'Unselect all'; $lang['strlocale'] = 'Locale'; + $lang['strcollation'] = 'Collation'; + $lang['strctype'] = 'Character Type'; // User-supplied SQL history $lang['strhistory'] = 'History'; diff --git a/lang/french.php b/lang/french.php index 5abda048..f75fac95 100644 --- a/lang/french.php +++ b/lang/french.php @@ -60,6 +60,7 @@ $lang['stralter'] = 'Modifier'; $lang['strok'] = 'OK'; $lang['strcancel'] = 'Annuler'; +$lang['strkill'] = 'Kill'; $lang['strac'] = 'Activer la complétion automatique'; $lang['strsave'] = 'Sauvegarder'; $lang['strreset'] = 'Réinitialiser'; @@ -138,6 +139,8 @@ $lang['strconfdropcred'] = 'For security reason, disconnecting will destroy yo $lang['strselectall'] = 'Sélectionner tout'; $lang['strunselectall'] = 'Desélectionner tout'; $lang['strlocale'] = 'Locale'; + $lang['strcollation'] = 'Tri'; + $lang['strctype'] = 'Type de cartactère'; // User-supplied SQL history $lang['strhistory'] = 'Historique'; @@ -180,6 +183,8 @@ $lang['strconfdropcred'] = 'For security reason, disconnecting will destroy yo $lang['strcannotdumponwindows'] = 'La sauvegarde de table complexe et des noms de schémas n\'est pas supporté sur Windows.'; $lang['strinvalidserverparam'] = 'Tentative de connexion avec un serveur invalide, il est possible que quelqu\'un essai de pirater votre système.'; $lang['strnoserversupplied'] = 'Aucun serveur fournis !'; +$lang['strbadpgdumppath'] = 'Export error: Failed to execute pg_dump (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.'; +$lang['strbadpgdumpallpath'] = 'Export error: Failed to execute pg_dumpall (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.'; // Tables $lang['strtable'] = 'Table'; @@ -367,6 +372,7 @@ $lang['strconfdropcred'] = 'For security reason, disconnecting will destroy yo $lang['strdatabasealtered'] = 'Base de données modifiée.'; $lang['strdatabasealteredbad'] = 'Échec lors de la modification de la base de données.'; $lang['strspecifydatabasetodrop'] = 'Vous devez spécifier au moins une base de données à supprimer'; +$lang['strtemplatedb'] = 'Template'; // Views $lang['strview'] = 'Vue'; @@ -456,6 +462,7 @@ $lang['strconfdropcred'] = 'For security reason, disconnecting will destroy yo $lang['strconfcluster'] = 'Êtes-vous sur de vouloir mettre en cluster « %s » ?'; $lang['strclusteredgood'] = 'Cluster effectué.'; $lang['strclusteredbad'] = 'Échec du cluster.'; +$lang['strconcurrently'] = 'Concurrently'; // Rules $lang['strrules'] = 'Règles'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index f864eb17..4ebe06b4 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -139,6 +139,8 @@ $lang['strselectall'] = 'Select all'; $lang['strunselectall'] = 'Unselect all'; $lang['strlocale'] = 'Locale'; + $lang['strcollation'] = 'Collation'; + $lang['strctype'] = 'Character Type'; // User-supplied SQL history $lang['strhistory'] = 'History'; diff --git a/lang/recoded/french.php b/lang/recoded/french.php index cc43b6cd..64bbfbb7 100644 --- a/lang/recoded/french.php +++ b/lang/recoded/french.php @@ -60,6 +60,7 @@ $lang['stralter'] = 'Modifier'; $lang['strok'] = 'OK'; $lang['strcancel'] = 'Annuler'; +$lang['strkill'] = 'Kill'; $lang['strac'] = 'Activer la complétion automatique'; $lang['strsave'] = 'Sauvegarder'; $lang['strreset'] = 'Réinitialiser'; @@ -133,10 +134,13 @@ $lang['strfile'] = 'Fichier'; $lang['strfileimported'] = 'Fichier importé.'; $lang['strtrycred'] = 'Utilisez ces identifiants pour tous les serveurs'; +$lang['strconfdropcred'] = 'For security reason, disconnecting will destroy your shared login information. Are you sure you want to disconnect ?'; $lang['stractionsonmultiplelines'] = 'Actions sur plusieurs lignes'; $lang['strselectall'] = 'Sélectionner tout'; $lang['strunselectall'] = 'Desélectionner tout'; $lang['strlocale'] = 'Locale'; + $lang['strcollation'] = 'Tri'; + $lang['strctype'] = 'Type de cartactère'; // User-supplied SQL history $lang['strhistory'] = 'Historique'; @@ -179,6 +183,8 @@ $lang['strcannotdumponwindows'] = 'La sauvegarde de table complexe et des noms de schémas n\'est pas supporté sur Windows.'; $lang['strinvalidserverparam'] = 'Tentative de connexion avec un serveur invalide, il est possible que quelqu\'un essai de pirater votre système.'; $lang['strnoserversupplied'] = 'Aucun serveur fournis !'; +$lang['strbadpgdumppath'] = 'Export error: Failed to execute pg_dump (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.'; +$lang['strbadpgdumpallpath'] = 'Export error: Failed to execute pg_dumpall (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.'; // Tables $lang['strtable'] = 'Table'; @@ -245,6 +251,7 @@ $lang['strspecifytabletoempty'] = 'Vous devez spécifier au moins une table à vider'; $lang['strspecifytabletodrop'] = 'Vous devez spécifier au moins une table à supprimer'; $lang['strspecifytabletovacuum'] = 'Vous devez spécifier au moins une table sur laquelle effectuer le vacuum'; + $lang['strnofieldsforinsert'] = 'Vous ne pouvez insérer de données dans une table sans champs.'; // Columns $lang['strcolprop'] = 'Propriétés de la Colonne'; @@ -365,6 +372,7 @@ $lang['strdatabasealtered'] = 'Base de données modifiée.'; $lang['strdatabasealteredbad'] = 'Échec lors de la modification de la base de données.'; $lang['strspecifydatabasetodrop'] = 'Vous devez spécifier au moins une base de données à supprimer'; +$lang['strtemplatedb'] = 'Template'; // Views $lang['strview'] = 'Vue'; @@ -454,6 +462,7 @@ $lang['strconfcluster'] = 'Êtes-vous sur de vouloir mettre en cluster « %s » ?'; $lang['strclusteredgood'] = 'Cluster effectué.'; $lang['strclusteredbad'] = 'Échec du cluster.'; +$lang['strconcurrently'] = 'Concurrently'; // Rules $lang['strrules'] = 'Règles'; -- 2.39.5