From 2f2542a423f8186c08aaeea8ce20b835f5a0d4ff Mon Sep 17 00:00:00 2001 From: soranzo Date: Wed, 12 May 2004 22:40:49 +0000 Subject: [PATCH] Move getLinkingKeys() to Postgres74.php. Small fixes and typos. --- classes/database/Postgres73.php | 45 +++---------------------------- classes/database/Postgres74.php | 47 +++++++++++++++++++++++++++++++-- display.php | 4 +-- views.php | 6 ++--- 4 files changed, 53 insertions(+), 49 deletions(-) diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index 24b00a9e..805d3a4c 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.101 2004/05/09 09:10:04 chriskl Exp $ + * $Id: Postgres73.php,v 1.102 2004/05/12 22:40:49 soranzo Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -76,7 +76,7 @@ class Postgres73 extends Postgres72 { /** * Sets the current schema search path - * @param $path An array of schemas in required search order + * @param $paths An array of schemas in required search order * @return 0 success * @return -1 Array not passed * @return -2 Array must contain at least one item @@ -235,7 +235,7 @@ class Postgres73 extends Postgres72 { /** * Given an array of attnums and a relation, returns an array mapping - * atttribute number to attribute name. + * attribute number to attribute name. * @param $table The table to get attributes for * @param $atts An array of attribute numbers * @return An array mapping attnum to attname @@ -939,45 +939,6 @@ class Postgres73 extends Postgres72 { // Constraint functions - /** - * A function for getting all linking fields on the foreign keys based on the table names - * @param $table array of table names - * @return an array of linked tables and fields - */ - function &getLinkingKeys($arrTables) { - $this->arrayClean($arrTables); - // Properly quote the tables - $tables = "'" . implode("', '", $arrTables) . "'"; - - $sql = " - SELECT - pgc1.relname AS p_table, - pgc2.relname AS f_table, - pfield.attname AS p_field, - cfield.attname AS f_field - FROM - pg_catalog.pg_constraint AS pc, - pg_catalog.pg_class AS pgc1, - pg_catalog.pg_class AS pgc2, - pg_catalog.pg_attribute AS pfield, - pg_catalog.pg_attribute AS cfield - WHERE - pc.contype = 'f' - AND pc.conrelid = pgc1.relfilenode - AND pc.confrelid = pgc2.relfilenode - AND pfield.attrelid = pc.conrelid - AND cfield.attrelid = pc.confrelid - AND pfield.attnum = ANY(pc.conkey) - AND cfield.attnum = ANY(pc.confkey) - AND pgc1.relname IN ($tables) - AND pgc2.relname IN ($tables) - AND pgc1.relnamespace = (SELECT oid FROM pg_catalog.pg_namespace - WHERE nspname='{$this->_schema}') - "; - - return $this->selectSet($sql); - } - /** * A helper function for getConstraints that translates * an array of attribute numbers to an array of field names. diff --git a/classes/database/Postgres74.php b/classes/database/Postgres74.php index 9653120a..45e45029 100644 --- a/classes/database/Postgres74.php +++ b/classes/database/Postgres74.php @@ -4,7 +4,7 @@ * A class that implements the DB interface for Postgres * Note: This class uses ADODB and returns RecordSets. * - * $Id: Postgres74.php,v 1.28 2004/05/09 09:10:04 chriskl Exp $ + * $Id: Postgres74.php,v 1.29 2004/05/12 22:40:49 soranzo Exp $ */ include_once('./classes/database/Postgres73.php'); @@ -140,7 +140,7 @@ class Postgres74 extends Postgres73 { /* This select excludes any indexes that are just base indexes for constraints. */ $sql = "SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, - pg_catalog.pg_get_indexdef(i.indexrelid, 0, true) as pg_get_indexdef + pg_catalog.pg_get_indexdef(i.indexrelid, 0, true) AS pg_get_indexdef FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i WHERE c.relname = '{$table}' AND pg_catalog.pg_table_is_visible(c.oid) AND c.oid = i.indrelid AND i.indexrelid = c2.oid @@ -195,6 +195,49 @@ class Postgres74 extends Postgres73 { // Constraint functions + /** + * A function for getting all linking columns on the foreign keys based on the table names + * @param $tables Array of table names + * @return A recordset of (constrained table, referenced table, constrained column, referenced column) + * @return -1 $tables isn't an array + */ + function &getLinkingKeys($tables) { + if (!is_array($tables)) return -1; + + $this->arrayClean($tables); + // Properly quote the tables list + $tables_list = "'" . implode("', '", $tables) . "'"; + + // ct = constrained table, rt = referenced table + // cc = constrained column, rc = referenced column + $sql = "SELECT + ct.relname AS p_table, + rt.relname AS f_table, + cc.attname AS p_field, + rc.attname AS f_field + FROM + pg_catalog.pg_constraint c, + pg_catalog.pg_class ct, + pg_catalog.pg_class rt, + pg_catalog.pg_attribute cc, + pg_catalog.pg_attribute rc + WHERE + c.contype = 'f' + AND c.conrelid = ct.relfilenode + AND c.confrelid = rt.relfilenode + AND cc.attrelid = c.conrelid + AND rc.attrelid = c.confrelid + AND cc.attnum = ANY (c.conkey) + AND rc.attnum = ANY (c.confkey) + AND ct.relname IN ($tables_list) + AND rt.relname IN ($tables_list) + AND ct.relnamespace = (SELECT oid FROM pg_catalog.pg_namespace + WHERE nspname='{$this->_schema}') + "; + + return $this->selectSet($sql); + } + /** * Returns a list of all constraints on a table * @param $table The table to find rules for diff --git a/display.php b/display.php index e2586341..aef91a8f 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.37 2004/05/09 06:56:48 chriskl Exp $ + * $Id: display.php,v 1.38 2004/05/12 22:40:49 soranzo Exp $ */ // Include application functions @@ -37,7 +37,7 @@ $attrs = &$data->getTableAttributes($_REQUEST['table']); $rs = &$data->browseRow($_REQUEST['table'], $key); - echo "
\n"; + echo "\n"; $elements = 0; $error = true; if ($rs->recordCount() == 1 && $attrs->recordCount() > 0) { diff --git a/views.php b/views.php index 032e96b7..92a13d9f 100644 --- a/views.php +++ b/views.php @@ -3,7 +3,7 @@ /** * Manage views in a database * - * $Id: views.php,v 1.31 2004/05/10 15:22:00 chriskl Exp $ + * $Id: views.php,v 1.32 2004/05/12 22:40:49 soranzo Exp $ */ // Include application functions @@ -170,7 +170,7 @@ if (!isset($_REQUEST['formView'])) $_REQUEST['formView'] = ''; if (!isset($_REQUEST['formComment'])) $_REQUEST['formComment'] = ''; - echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateview']}

\n"; + echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateviewwiz']}

\n"; $misc->printMsg($msg); $tblCount = count($_POST['formTables']); // If we have a message that means an error occurred in doSaveCreate, which means POST['formTables'] has quotes @@ -281,7 +281,7 @@ global $PHP_SELF, $lang; $tables = &$data->getTables(); - echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateview']}

\n"; + echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateviewwiz']}

\n"; $misc->printMsg($msg); echo "\n"; echo "\n"; -- 2.39.5