From 04df114f1cc3aa7410a9afa98bd99dd54a2712be Mon Sep 17 00:00:00 2001 From: chriskl Date: Tue, 8 Apr 2003 12:45:17 +0000 Subject: [PATCH] begin add foreign key, add pgsql->http encoding maps for all db encodings --- HISTORY | 1 + classes/database/Postgres.php | 41 +++++++--- classes/database/Postgres72.php | 6 +- constraints.php | 138 +++++++++++++++++++++++++++++++- display.php | 6 +- libraries/lib.inc.php | 20 ++++- 6 files changed, 192 insertions(+), 20 deletions(-) diff --git a/HISTORY b/HISTORY index 6acf3c60..d1117907 100644 --- 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 ------------------- diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index bc908a0e..5bbdb615 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -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 diff --git a/classes/database/Postgres72.php b/classes/database/Postgres72.php index 92a53736..ca7bff30 100644 --- a/classes/database/Postgres72.php +++ b/classes/database/Postgres72.php @@ -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 diff --git a/constraints.php b/constraints.php index 05ba0e3d..70c9c580 100644 --- a/constraints.php +++ b/constraints.php @@ -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 @@ -13,6 +13,131 @@ $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 "

", htmlspecialchars($_REQUEST['database']), ": {$lang['strtables']}: ", + htmlspecialchars($_REQUEST['table']), ": {$lang['straddfk']}

\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 "
\n"; + + echo "\n"; + echo ""; + echo ""; + echo ""; + echo "\n"; + echo "\n"; + echo ""; + echo "\n"; + echo ""; + echo ""; + echo ""; + echo "
{$lang['strname']}
_maxNameLen}\" />
{$lang['strtablecolumnlist']} {$lang['strindexcolumnlist']}
" . $selColumns->fetch() . "" . $buttonRemove->fetch() . $buttonAdd->fetch() . "" . $selIndex->fetch() . "
{$lang['strfktarget']}
_maxNameLen}\" />
\n"; + + echo "

\n"; + echo $misc->form; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "

\n"; + echo "
\n"; + + echo "

href}&table=", urlencode($_REQUEST['table']), + "\">{$lang['strshowallconstraints']}

\n"; + break; + default: + echo "

", htmlspecialchars($_REQUEST['database']), ": {$lang['strtables']}: ", + htmlspecialchars($_REQUEST['table']), ": {$lang['straddfk']}

\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 "
\n"; + + echo "\n"; + echo ""; + echo ""; + echo ""; + echo "\n"; + echo "\n"; + echo ""; + echo "\n"; + echo ""; + echo ""; + echo ""; + echo "
{$lang['strname']}
_maxNameLen}\" />
{$lang['strtablecolumnlist']} {$lang['strindexcolumnlist']}
" . $selColumns->fetch() . "" . $buttonRemove->fetch() . $buttonAdd->fetch() . "" . $selIndex->fetch() . "
{$lang['strfktarget']}
_maxNameLen}\" />
\n"; + + echo "

\n"; + echo $misc->form; + echo "\n"; + echo "\n"; + echo "

\n"; + echo "
\n"; + + echo "

href}&table=", urlencode($_REQUEST['table']), + "\">{$lang['strshowallconstraints']}

\n"; + break; + } + + } + /** * Confirm and then actually add a PRIMARY KEY or UNIQUE constraint */ @@ -240,7 +365,9 @@ echo "href}&table=", urlencode($_REQUEST['table']), "\">{$lang['stradduniq']} |\n"; echo "href}&table=", urlencode($_REQUEST['table']), - "\">{$lang['straddpk']}

\n"; + "\">{$lang['straddpk']} |\n"; + echo "href}&table=", urlencode($_REQUEST['table']), + "\">{$lang['straddfk']}

\n"; } $misc->printHeader($lang['strtables'] . ' - ' . $_REQUEST['table'] . ' - ' . $lang['strconstraints'], @@ -253,6 +380,13 @@ $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; diff --git a/display.php b/display.php index 9fa3d82b..9c1b4f4e 100644 --- a/display.php +++ b/display.php @@ -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 "", htmlspecialchars($k), ""; } - + $i = 0; reset($rs->f); while (!$rs->EOF) { @@ -68,7 +68,7 @@ echo "\n"; echo "

", $rs->recordCount(), " {$lang['strrows']}

\n"; } - else echo "

No data.

\n"; + else echo "

{$lang['strnodata']}

\n"; echo "

{$_REQUEST['return_desc']}

\n"; diff --git a/libraries/lib.inc.php b/libraries/lib.inc.php index 365bebca..bc8584bc 100644 --- a/libraries/lib.inc.php +++ b/libraries/lib.inc.php @@ -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 @@ -152,7 +152,10 @@ } } - // Get database encoding + } + + // Get database encoding + if (isset($localData)) { $dbEncoding = $localData->getDatabaseEncoding(); // Set client encoding to database encoding @@ -170,5 +173,18 @@ $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']; + } + */ ?> -- 2.39.5