begin add foreign key, add pgsql->http encoding maps for all db encodings
authorchriskl <chriskl>
Tue, 8 Apr 2003 12:45:17 +0000 (12:45 +0000)
committerchriskl <chriskl>
Tue, 8 Apr 2003 12:45:17 +0000 (12:45 +0000)
HISTORY
classes/database/Postgres.php
classes/database/Postgres72.php
constraints.php
display.php
libraries/lib.inc.php

diff --git a/HISTORY b/HISTORY
index 6acf3c6085b25daca7307f1dc7b99bff45a6d620..d111790704fdd22f4ebfdb712ed354d3ffdb97c8 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -9,6 +9,7 @@ Version 3.0.0-dev-3
 * Japanese translations
 * Trigger definitions
 * ADODB upgrade
+* Allow editing of non-null unique
 
 Version 3.0.0-dev-2
 -------------------
index bc908a0e3291e2d8a5bb96a3b408551e97d11441..5bbdb6159a9c5b6b0ae9851aa51c5d99996da66f 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.70 2003/03/27 13:47:15 chriskl Exp $
+ * $Id: Postgres.php,v 1.71 2003/04/08 12:45:18 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -59,18 +59,35 @@ class Postgres extends BaseDB {
        // database encoding does not appear in this list, then its HTTP
        // encoding name is the same as its database encoding name.
        var $codemap = array(
+               'ALT' => 'CP866',
+               'EUC_CN' => 'GB2312',
+               'EUC_JP' => 'EUCJP',
+               'EUC_KR' => 'EUCKR',
+               'EUC_TW' => 'EUCTW', 
+               'ISO_8859-5' => 'ISO 8859-5',
+               'ISO_8859-6' => 'ISO 8859-6',
+               'ISO_8859-7' => 'ISO 8859-7',
+               'ISO_8859-8' => 'ISO 8859-8',
+               'JOHAB' => 'CP1361',
+               'KOI8' => 'KOI8-R',
+               'LATIN1' => 'ISO 8859-1',
+               'LATIN2' => 'ISO 8859-2',
+               'LATIN3' => 'ISO 8859-3',
+               'LATIN4' => 'ISO 8859-4',
+               // The following encoding map is a known error in PostgreSQL < 7.2
+               // See the constructor for Postgres72.
+               'LATIN5' => 'ISO 8859-5',
+               'LATIN6' => 'ISO 8859-10',
+               'LATIN7' => 'ISO 8859-13',
+               'LATIN8' => 'ISO 8859-14',
+               'LATIN9' => 'ISO 8859-15',
+               'LATIN10' => 'ISO 8859-16',
                'SQL_ASCII' => 'ASCII',
-               'LATIN1' => 'ISO-8859-1',
-               'LATIN2' => 'ISO-8859-2',
-               'LATIN3' => 'ISO-8859-3',
-               'LATIN4' => 'ISO-8859-4',
-               'LATIN5' => 'ISO-8859-9',
-               'LATIN6' => 'ISO-8859-10',
-               'LATIN7' => 'ISO-8859-13',
-               'LATIN8' => 'ISO-8859-14',
-               'LATIN9' => 'ISO-8859-15',
-               'LATIN10' => 'ISO-8859-16',
-               'UNICODE' => 'UTF-8'
+               'TCVN' => 'CP1258',
+               'UNICODE' => 'UTF8',
+               'WIN' => 'CP1251',
+               'WIN874' => 'CP874',
+               'WIN1256' => 'CP1256'
        );
        
        // List of all legal privileges that can be applied to different types
index 92a5373605d7e9c314d1d3c4aa44bbde4779be56..ca7bff30ac2f90ec1ba7e90e0b79489720ae9681 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres72.php,v 1.32 2003/03/27 12:56:30 chriskl Exp $
+ * $Id: Postgres72.php,v 1.33 2003/04/08 12:45:18 chriskl Exp $
  */
 
 
@@ -37,6 +37,10 @@ class Postgres72 extends Postgres71 {
         */
        function Postgres72($host, $port, $database, $user, $password) {
                $this->Postgres71($host, $port, $database, $user, $password);
+
+               // Correct the error in the encoding tables, that was
+               // fixed in PostgreSQL 7.2
+               $this->codemap['LATIN5'] = 'ISO 8859-9';
        }
 
        // Table functions
index 05ba0e3ddd5253e00e20674fae6fab5b6d571bd0..70c9c580261a8696214198c984f6bee2bc7b48fe 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List constraints on a table
         *
-        * $Id: constraints.php,v 1.11 2003/03/26 01:24:17 chriskl Exp $
+        * $Id: constraints.php,v 1.12 2003/04/08 12:45:17 chriskl Exp $
         */
 
        // Include application functions
        $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
        $PHP_SELF = $_SERVER['PHP_SELF'];
 
+
+       /**
+        * Confirm and then actually add a FOREIGN KEY constraint
+        */
+       function addForeignKey($stage, $msg = '') {
+               global $PHP_SELF, $data, $localData, $misc;
+               global $lang;
+
+               if (!isset($_POST['name'])) $_POST['name'] = '';
+               if (!isset($_POST['target'])) $_POST['target'] = '';
+
+               switch ($stage) {
+                       case 2:
+                               echo "<h2>", htmlspecialchars($_REQUEST['database']), ": {$lang['strtables']}: ",
+                                       htmlspecialchars($_REQUEST['table']), ": {$lang['straddfk']}</h2>\n";
+                               $misc->printMsg($msg);
+
+                               $attrs = &$localData->getTableAttributes($_REQUEST['target']);
+
+                               $selColumns = new XHTML_select('TableColumnList', true, 10);
+                               $selColumns->set_style('width: 10em;');
+
+                               if ($attrs->recordCount() > 0) {
+                                       while (!$attrs->EOF) {
+                                               $selColumns->add(new XHTML_Option($attrs->f['attname']));
+                                               $attrs->moveNext();
+                                       }
+                               }
+
+                               $selIndex = new XHTML_select('IndexColumnList[]', true, 10);
+                               $selIndex->set_style('width: 10em;');
+                               $selIndex->set_attribute('id', 'IndexColumnList');
+                               $buttonAdd = new XHTML_Button('add', '>>');
+                               $buttonAdd->set_attribute('onclick', 'buttonPressed(this);');
+                               $buttonAdd->set_attribute('type', 'button');
+
+                               $buttonRemove = new XHTML_Button('remove', '<<');
+                               $buttonRemove->set_attribute('onclick', 'buttonPressed(this);');
+                               $buttonRemove->set_attribute('type', 'button');
+
+                               echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";    
+
+                               echo "<table>\n";
+                               echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strname']}</th></tr>";
+                               echo "<tr>";
+                               echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>";
+                               echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th><th class=data>{$lang['strindexcolumnlist']}</th></tr>\n";
+                               echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
+                               echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
+                               echo "<td class=data1>" . $selIndex->fetch() . "</td></tr>\n";
+                               echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strfktarget']}</th></tr>";
+                               echo "<tr>";
+                               echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"target\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>";
+                               echo "</table>\n";
+
+                               echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_foreign_key\">\n";
+                               echo $misc->form;
+                               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+                               echo "<input type=\"hidden\" name=\"name\" value=\"", htmlspecialchars($_REQUEST['name']), "\">\n";
+                               echo "<input type=\"hidden\" name=\"target\" value=\"", htmlspecialchars($_REQUEST['target']), "\">\n";
+                               echo "<input type=\"hidden\" name=\"IndexColumnList\" value=\"", htmlspecialchars(serialize($_REQUEST['IndexColumnList'])), "\">\n";
+                               echo "<input type=\"hidden\" name=\"stage\" value=\"3\">\n";
+                               echo "<input type=\"submit\" value=\"{$lang['stradd']}\"> <input type=\"reset\" value=\"{$lang['strreset']}\"></p>\n";
+                               echo "</form>\n";
+
+                               echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}&table=", urlencode($_REQUEST['table']),
+                                       "\">{$lang['strshowallconstraints']}</a></p>\n";
+                               break;
+                       default:
+                               echo "<h2>", htmlspecialchars($_REQUEST['database']), ": {$lang['strtables']}: ",
+                                       htmlspecialchars($_REQUEST['table']), ": {$lang['straddfk']}</h2>\n";
+                               $misc->printMsg($msg);
+
+                               $attrs = &$localData->getTableAttributes($_REQUEST['table']);
+
+                               $selColumns = new XHTML_select('TableColumnList', true, 10);
+                               $selColumns->set_style('width: 10em;');
+
+                               if ($attrs->recordCount() > 0) {
+                                       while (!$attrs->EOF) {
+                                               $selColumns->add(new XHTML_Option($attrs->f['attname']));
+                                               $attrs->moveNext();
+                                       }
+                               }
+
+                               $selIndex = new XHTML_select('IndexColumnList[]', true, 10);
+                               $selIndex->set_style('width: 10em;');
+                               $selIndex->set_attribute('id', 'IndexColumnList');
+                               $buttonAdd = new XHTML_Button('add', '>>');
+                               $buttonAdd->set_attribute('onclick', 'buttonPressed(this);');
+                               $buttonAdd->set_attribute('type', 'button');
+
+                               $buttonRemove = new XHTML_Button('remove', '<<');
+                               $buttonRemove->set_attribute('onclick', 'buttonPressed(this);');
+                               $buttonRemove->set_attribute('type', 'button');
+
+                               echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";    
+
+                               echo "<table>\n";
+                               echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strname']}</th></tr>";
+                               echo "<tr>";
+                               echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>";
+                               echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\">&nbsp;</th><th class=data>{$lang['strindexcolumnlist']}</th></tr>\n";
+                               echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
+                               echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
+                               echo "<td class=data1>" . $selIndex->fetch() . "</td></tr>\n";
+                               echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strfktarget']}</th></tr>";
+                               echo "<tr>";
+                               echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"target\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>";
+                               echo "</table>\n";
+
+                               echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_foreign_key\">\n";
+                               echo $misc->form;
+                               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+                               echo "<input type=\"hidden\" name=\"stage\" value=\"2\">\n";
+                               echo "<input type=\"submit\" value=\"{$lang['stradd']}\"> <input type=\"reset\" value=\"{$lang['strreset']}\"></p>\n";
+                               echo "</form>\n";
+
+                               echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}&table=", urlencode($_REQUEST['table']),
+                                       "\">{$lang['strshowallconstraints']}</a></p>\n";
+                               break;
+               }
+
+       }
+
        /**
         * Confirm and then actually add a PRIMARY KEY or UNIQUE constraint
         */
                echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=add_unique_key&{$misc->href}&table=", urlencode($_REQUEST['table']),
                        "\">{$lang['stradduniq']}</a> |\n";
                echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=add_primary_key&{$misc->href}&table=", urlencode($_REQUEST['table']),
-                       "\">{$lang['straddpk']}</a></p>\n";
+                       "\">{$lang['straddpk']}</a> |\n";
+               echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=add_foreign_key&{$misc->href}&table=", urlencode($_REQUEST['table']),
+                       "\">{$lang['straddfk']}</a></p>\n";
        }
 
        $misc->printHeader($lang['strtables'] . ' - ' . $_REQUEST['table'] . ' - ' . $lang['strconstraints'],
                $misc->printBody();
 
        switch ($action) {
+               case 'add_foreign_key':
+                       addForeignKey(1);
+                       break;
+               case 'save_add_foreign_key':
+                       if (isset($_POST['cancel'])) doDefault();
+                       else addForeignKey($_REQUEST['stage']);
+                       break;
                case 'add_unique_key':
                        addPrimaryOrUniqueKey('unique', true);
                        break;
index 9fa3d82bf85fd8b7b98b3d5ffe37693d3cb75235..9c1b4f4ea83cab41ca5d9a454491054e06baf84c 100644 (file)
@@ -9,7 +9,7 @@
         * @param $return_desc The return link name
         * @param $page The current page
         *
-        * $Id: display.php,v 1.10 2003/04/04 03:59:36 chriskl Exp $
+        * $Id: display.php,v 1.11 2003/04/08 12:45:18 chriskl Exp $
         */
 
        // Include application functions
@@ -52,7 +52,7 @@
                while(list($k, ) = each($rs->f)) {
                        echo "<th class=data>", htmlspecialchars($k), "</th>";
                }
-               
+
                $i = 0;
                reset($rs->f);
                while (!$rs->EOF) {
@@ -68,7 +68,7 @@
                echo "</table>\n";
                echo "<p>", $rs->recordCount(), " {$lang['strrows']}</p>\n";
        }
-       else echo "<p>No data.</p>\n";
+       else echo "<p>{$lang['strnodata']}</p>\n";
        
        echo "<p><a class=\"navlink\" href=\"{$_REQUEST['return_url']}\">{$_REQUEST['return_desc']}</a></p>\n";
 
index 365bebca1fea8882b4b625485b4ea9aa46951244..bc8584bcb5747f6de649436a449753228a3b49df 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Function library read in upon startup
         *
-        * $Id: lib.inc.php,v 1.30 2003/04/08 07:09:51 chriskl Exp $
+        * $Id: lib.inc.php,v 1.31 2003/04/08 12:45:19 chriskl Exp $
         */
 
        // Application name 
                        }
                }
                
-               // Get database encoding
+       }
+
+       // Get database encoding
+       if (isset($localData)) {
                $dbEncoding = $localData->getDatabaseEncoding();
                
                // Set client encoding to database encoding
                                $lang['appcharset'] = $dbEncoding;
                }
        }
+       // This experiment didn't quite work - try again later.
+       /*
+       else {
+               $status = $data->setClientEncoding('UNICODE');
+               if ($status != 0) {
+                       echo $lang['strbadencoding'];
+                       exit;
+               }
+
+               // Override $lang['appcharset']
+               $lang['appcharset'] = $data->codemap['UNICODE'];
+       }
+       */
 
 ?>