add support for database level collation
authorGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Fri, 14 Aug 2009 02:29:19 +0000 (22:29 -0400)
committerGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Fri, 14 Aug 2009 02:29:19 +0000 (22:29 -0400)
all_db.php
classes/database/Postgres.php
classes/database/Postgres83.php
lang/english.php
lang/french.php
lang/recoded/english.php
lang/recoded/french.php

index 331316031c56bc90f1b86d750b9a4d75cdf79ef8..b2b515b38cadbac4978882e9a5d9453364473f7d 100644 (file)
                echo "\t\t\t</select>\n";
                echo "\t\t</td>\n\t</tr>\n";
 
+               // ENCODING
                echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strencoding']}</th>\n";
                echo "\t\t<td class=\"data1\">\n";
                echo "\t\t\t<select name=\"formEncoding\">\n";
                echo "\t\t\t</select>\n";
                echo "\t\t</td>\n\t</tr>\n";
 
+               if ($data->hasDatabaseCollation()) {
+                       if (!isset($_POST['formCollate'])) $_POST['formCollate'] = '';
+                       if (!isset($_POST['formCType'])) $_POST['formCType'] = '';
+
+                       // LC_COLLATE
+                       echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcollation']}</th>\n";
+                       echo "\t\t<td class=\"data1\">\n";
+                       echo "\t\t\t<input name=\"formCollate\" value=\"", htmlspecialchars($_POST['formCollate']), "\" />\n";
+                       echo "\t\t</td>\n\t</tr>\n";
+
+                       // LC_CTYPE
+                       echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strctype']}</th>\n";
+                       echo "\t\t<td class=\"data1\">\n";
+                       echo "\t\t\t<input name=\"formCType\" value=\"", htmlspecialchars($_POST['formCType']), "\" />\n";
+                       echo "\t\t</td>\n\t</tr>\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";
                // 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']);
                                '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'),
 
                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']);
index 9b4d0d172f23e0605bacd4b01a4ead02c3a02abd..6b20edb624401a7255ab6dea3f29b3969594f3ba 100755 (executable)
@@ -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; }
index cc399dc547c5fb31dc7fe3a0660815c8ff68383d..7fcc2ee4ab75591be0dcf200ed249c64700384fd 100644 (file)
@@ -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; }
 
 }
 
index a07585973330557eea74e07d68d8146e714365ee..66c6704562c1faa850c64ce5ffd48f157d09fbf2 100644 (file)
        $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';
index 5abda048c7446114181c340d6eecf2db94ef46f6..f75fac959864654bf4fd4bcaba4cdef8a1fe3a7d 100644 (file)
@@ -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';
index f864eb17e475e244aa74e2f1d0b7239cc1599479..4ebe06b40fab2d8ea74132e92075f11f84670c5a 100644 (file)
        $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';
index cc43b6cdc6708747caa9504be1dd1bcb129f7b31..64bbfbb75a992592948803cb1fba588a7a2ac543 100644 (file)
@@ -60,6 +60,7 @@
        $lang['stralter'] = 'Modifier';
        $lang['strok'] = 'OK';
        $lang['strcancel'] = 'Annuler';
+$lang['strkill']  =  'Kill';
        $lang['strac']  =  'Activer la compl&#233;tion automatique';
        $lang['strsave'] = 'Sauvegarder';
        $lang['strreset'] = 'R&#233;initialiser';
        $lang['strfile']  =  'Fichier';
        $lang['strfileimported']  =  'Fichier import&#233;.';
        $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&#233;lectionner tout';
        $lang['strunselectall']  =  'Des&#233;lectionner tout';
        $lang['strlocale']  =  'Locale';
+       $lang['strcollation']  =  'Tri';
+       $lang['strctype']  =  'Type de cartact&#232;re';
 
        // User-supplied SQL history
        $lang['strhistory']  =  'Historique';
        $lang['strcannotdumponwindows']  =  'La sauvegarde de table complexe et des noms de sch&#233;mas n\'est pas support&#233; sur Windows.';
        $lang['strinvalidserverparam'] = 'Tentative de connexion avec un serveur invalide, il est possible que quelqu\'un essai de pirater votre syst&#232;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';
        $lang['strspecifytabletoempty']  =  'Vous devez sp&#233;cifier au moins une table &#224; vider';
        $lang['strspecifytabletodrop']  =  'Vous devez sp&#233;cifier au moins une table &#224; supprimer';
        $lang['strspecifytabletovacuum']  =  'Vous devez sp&#233;cifier au moins une table sur laquelle effectuer le vacuum';
+       $lang['strnofieldsforinsert']  =  'Vous ne pouvez ins&#233;rer de donn&#233;es dans une table sans champs.';
 
        // Columns
        $lang['strcolprop']  =  'Propri&#233;t&#233;s de la Colonne';
        $lang['strdatabasealtered']  =  'Base de donn&#233;es modifi&#233;e.';
        $lang['strdatabasealteredbad']  =  '&#201;chec lors de la modification de la base de donn&#233;es.';
        $lang['strspecifydatabasetodrop']  =  'Vous devez sp&#233;cifier au moins une base de donn&#233;es &#224; supprimer';
+$lang['strtemplatedb']  =  'Template';
 
        // Views
        $lang['strview'] = 'Vue';
        $lang['strconfcluster']  =  '&#202;tes-vous sur de vouloir mettre en cluster &#171; %s &#187; ?';
        $lang['strclusteredgood']  =  'Cluster effectu&#233;.';
        $lang['strclusteredbad']  =  '&#201;chec du cluster.';
+$lang['strconcurrently']  =  'Concurrently';
 
        // Rules
        $lang['strrules'] = 'R&#232;gles';