* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.150 2003/10/06 15:26:23 chriskl Exp $
+ * $Id: Postgres.php,v 1.151 2003/10/08 02:14:24 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
return -99;
}
+ // Schema functions
+
+ /**
+ * Sets the current working schema. This is a do nothing method for
+ * < 7.3 and is just here for polymorphism's sake.
+ * @param $schema The the name of the schema to work in
+ * @return 0 success
+ */
+ function setSchema($schema) {
+ return 0;
+ }
+
// Table functions
/**
$sql .= ")";
+ // @@@@ DUMP CLUSTERING INFORMATION
+
// Inherits
/*
* XXX: This is currently commented out as handling inheritance isn't this simple.
/**
* Return all tables in current database
+ * @param $all True to fetch all tables, false for just in current schema
* @return All tables, sorted alphabetically
*/
- function &getTables() {
+ function &getTables($all = false) {
global $conf;
- if (!$conf['show_system']) $where = "WHERE tablename NOT LIKE 'pg_%' ";
+ if (!$conf['show_system'] || $all) $where = "WHERE tablename NOT LIKE 'pg_%' ";
else $where = '';
- $sql = "SELECT tablename, tableowner FROM pg_tables {$where}ORDER BY tablename";
+ $sql = "SELECT NULL AS schemaname, tablename, tableowner FROM pg_tables {$where}ORDER BY tablename";
return $this->selectSet($sql);
}
/**
* Adds a foreign key constraint to a table
- * @param $table The table to which to add the foreign key
+ * @param $targschema The schema that houses the target table to which to add the foreign key
+ * @param $targtable The table to which to add the foreign key
* @param $target The table that contains the target columns
* @param $sfields (array) An array of source fields over which to add the foreign key
* @param $tfields (array) An array of target fields over which to add the foreign key
* @return 0 success
* @return -1 no fields given
*/
- function addForeignKey($table, $target, $sfields, $tfields, $upd_action, $del_action, $name = '') {
+ function addForeignKey($table, $targschema, $targtable, $sfields, $tfields, $upd_action, $del_action, $name = '') {
if (!is_array($sfields) || sizeof($sfields) == 0 ||
!is_array($tfields) || sizeof($tfields) == 0) return -1;
$this->fieldClean($table);
- $this->fieldClean($target);
+ $this->fieldClean($targschema);
+ $this->fieldClean($targtable);
$this->fieldArrayClean($sfields);
$this->fieldArrayClean($tfields);
$this->fieldClean($name);
$sql = "ALTER TABLE \"{$table}\" ADD ";
if ($name != '') $sql .= "CONSTRAINT \"{$name}\" ";
$sql .= "FOREIGN KEY (\"" . join('","', $sfields) . "\") ";
- $sql .= "REFERENCES \"{$target}\"(\"" . join('","', $tfields) . "\") ";
+ $sql .= "REFERENCES ";
+ // Target table needs to be fully qualified
+ if ($this->hasSchemas()) {
+ $sql .= "\"{$targschema}\".";
+ }
+ $sql .= "\"{$targtable}\"(\"" . join('","', $tfields) . "\") ";
if ($upd_action != 'NO ACTION') $sql .= " ON UPDATE {$upd_action}";
if ($del_action != 'NO ACTION') $sql .= " ON DELETE {$del_action}";
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.65 2003/10/06 15:26:23 chriskl Exp $
+ * $Id: Postgres73.php,v 1.66 2003/10/08 02:14:24 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
}
/**
- * Return all tables in current database
+ * Return all tables in current database (and schema)
+ * @param $all True to fetch all tables, false for just in current schema
* @return All tables, sorted alphabetically
*/
- function &getTables() {
- $sql = "SELECT tablename, tableowner FROM pg_catalog.pg_tables
- WHERE schemaname='{$this->_schema}' ORDER BY tablename";
+ function &getTables($all = false) {
+ if ($all) {
+ // Exclude pg_catalog and information_schema tables
+ $sql = "SELECT schemaname, tablename, tableowner FROM pg_catalog.pg_tables
+ WHERE schemaname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')
+ ORDER BY schemaname, tablename";
+ } else {
+ $sql = "SELECT tablename, tableowner FROM pg_catalog.pg_tables
+ WHERE schemaname='{$this->_schema}' ORDER BY tablename";
+ }
return $this->selectSet($sql);
}
return $this->execute($sql);
}
+ // Inheritance functions\r
+ \r
+ /**\r
+ * Finds the names and schemas of parent tables (in order)\r
+ * @param $table The table to find the parents for\r
+ * @return A recordset\r
+ */\r
+ function &getTableParents($table) {\r
+ $this->clean($table);\r
+ \r
+ $sql = "\r
+ SELECT \r
+ pn.nspname AS schemaname, relname\r
+ FROM\r
+ pg_catalog.pg_class pc, pg_catalog.pg_inherits pi, pg_catalog.pg_namespace pn\r
+ WHERE\r
+ pc.oid=pi.inhparent
+ AND pc.relnamespace=pn.oid\r
+ AND pi.inhrelid = (SELECT oid from pg_catalog.pg_class WHERE relname='{$table}'
+ AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = '{$this->_schema}'))\r
+ ORDER BY\r
+ pi.inhseqno\r
+ ";\r
+ \r
+ return $this->selectSet($sql); \r
+ } \r
+\r
+\r
+ /**\r
+ * Finds the names and schemas of child tables\r
+ * @param $table The table to find the children for\r
+ * @return A recordset\r
+ */\r
+ function &getTableChildren($table) {\r
+ $this->clean($table);\r
+ \r
+ $sql = "\r
+ SELECT \r
+ pn.nspname AS schemaname, relname\r
+ FROM\r
+ pg_catalog.pg_class pc, pg_catalog.pg_inherits pi, pg_catalog.pg_namespace pn\r
+ WHERE\r
+ pc.oid=pi.inhrelid
+ AND pc.relnamespace=pn.oid\r
+ AND pi.inhparent = (SELECT oid from pg_catalog.pg_class WHERE relname='{$table}'
+ AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = '{$this->_schema}'))\r
+ ";\r
+ \r
+ return $this->selectSet($sql); \r
+ }
+
// View functions
/**
/**
* List constraints on a table
*
- * $Id: constraints.php,v 1.21 2003/10/03 07:38:54 chriskl Exp $
+ * $Id: constraints.php,v 1.22 2003/10/08 02:14:24 chriskl Exp $
*/
// Include application functions
* Show confirmation of cluster index and perform actual cluster
*/
function doClusterIndex($confirm) {
- global $localData, $database, $misc;
+ global $localData, $database, $misc, $action;
global $PHP_SELF, $lang;
if ($confirm) {
+ // Default analyze to on
+ if ($action == 'confirm_cluster_constraint') $_REQUEST['analyze'] = 'on';
+
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
$misc->printVal($_REQUEST['table']), ": " , $misc->printVal($_REQUEST['constraint']), ": {$lang['strcluster']}</h2>\n";
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
echo "<input type=\"hidden\" name=\"constraint\" value=\"", htmlspecialchars($_REQUEST['constraint']), "\" />\n";
echo $misc->form;
- echo "<p><input type=\"checkbox\" name=\"analyze\" /> {$lang['stranalyze']}</p>\n";
+ echo "<p><input type=\"checkbox\" name=\"analyze\"", (isset($_REQUEST['analyze']) ? ' checked="checked"' : ''), " /> {$lang['stranalyze']}</p>\n";
echo "<input type=\"submit\" name=\"cluster\" value=\"{$lang['strcluster']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
echo "</form>\n";
// Initialise variables
if (!isset($_POST['upd_action'])) $_POST['upd_action'] = null;
if (!isset($_POST['del_action'])) $_POST['del_action'] = null;
+ $_REQUEST['target'] = unserialize($_REQUEST['target']);
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
$misc->printVal($_REQUEST['table']), ": {$lang['straddfk']}</h2>\n";
$misc->printMsg($msg);
- $attrs = &$localData->getTableAttributes($_REQUEST['target']);
+ // Unserialize target and fetch appropriate table. This is a bit messy
+ // because the table could be in another schema.
+ if ($localData->hasSchemas()) {
+ $localData->setSchema($_REQUEST['target']['schemaname']);
+ }
+ $attrs = &$localData->getTableAttributes($_REQUEST['target']['tablename']);
+ if ($localData->hasSchemas()) {
+ $localData->setSchema($_REQUEST['schema']);
+ }
$selColumns = new XHTML_select('TableColumnList', true, 10);
$selColumns->set_style('width: 10em;');
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=\"target\" value=\"", htmlspecialchars(serialize($_REQUEST['target'])), "\" />\n";
echo "<input type=\"hidden\" name=\"SourceColumnList\" value=\"", htmlspecialchars($_REQUEST['SourceColumnList']), "\" />\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 "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></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;
case 3:
+ // Unserialize target
+ $_POST['target'] = unserialize($_POST['target']);
+
// Check that they've given at least one column
if (isset($_POST['SourceColumnList'])) $temp = unserialize($_POST['SourceColumnList']);
if (!isset($_POST['IndexColumnList']) || !is_array($_POST['IndexColumnList'])
|| sizeof($_POST['IndexColumnList']) == 0 || !isset($temp)
|| !is_array($temp) || sizeof($temp) == 0) addForeignKey(2, $lang['strfkneedscols']);
else {
- $status = $localData->addForeignKey($_POST['table'], $_POST['target'], unserialize($_POST['SourceColumnList']),
- $_POST['IndexColumnList'], $_POST['upd_action'], $_POST['del_action'], $_POST['name']);
+ $status = $localData->addForeignKey($_POST['table'], $_POST['target']['schemaname'], $_POST['target']['tablename'],
+ unserialize($_POST['SourceColumnList']), $_POST['IndexColumnList'], $_POST['upd_action'], $_POST['del_action'], $_POST['name']);
if ($status == 0)
doDefault($lang['strfkadded']);
else
echo "<tr>";
echo "<td class=\"data1\" colspan=\"3\"><select name=\"target\">";
while (!$tables->EOF) {
- echo "<option value=\"", htmlspecialchars($tables->f['tablename']), "\">",
- htmlspecialchars($tables->f['tablename']), "</option>\n";
+ $key = array('schemaname' => $tables->f['schemaname'], 'tablename' => $tables->f['tablename']);
+ $key = serialize($key);
+ echo "<option value=\"", htmlspecialchars($key), "\">";
+ if ($localData->hasSchemas() && $tables->f['schemaname'] != $_REQUEST['schema']) {
+ echo htmlspecialchars($tables->f['schemaname']), '.';
+ }
+ echo htmlspecialchars($tables->f['tablename']), "</option>\n";
$tables->moveNext();
}
echo "</select>\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 "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></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;
}
echo $misc->form;
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
echo "<input type=\"hidden\" name=\"type\" value=\"", htmlspecialchars($type), "\" />\n";
- echo "<input type=\"submit\" value=\"{$lang['stradd']}\" /> <input type=\"reset\" value=\"{$lang['strreset']}\" /></p>\n";
+ echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
echo "</form>\n";
-
- echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}&table=", urlencode($_REQUEST['table']),
- "\">{$lang['strshowallconstraints']}</a></p>\n";
}
else {
if ($_POST['type'] == 'primary') {
/**
* List indexes on a table
*
- * $Id: indexes.php,v 1.18 2003/10/03 07:38:54 chriskl Exp $
+ * $Id: indexes.php,v 1.19 2003/10/08 02:14:24 chriskl Exp $
*/
// Include application functions
* Show confirmation of cluster index and perform actual cluster
*/
function doClusterIndex($confirm) {
- global $localData, $database, $misc;
+ global $localData, $database, $misc, $action;
global $PHP_SELF, $lang;
if ($confirm) {
+ // Default analyze to on
+ if ($action == 'confirm_cluster_index') $_REQUEST['analyze'] = 'on';
+
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
$misc->printVal($_REQUEST['table']), ": " , $misc->printVal($_REQUEST['index']), ": {$lang['strcluster']}</h2>\n";
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
echo "<input type=\"hidden\" name=\"index\" value=\"", htmlspecialchars($_REQUEST['index']), "\" />\n";
echo $misc->form;
- echo "<p><input type=\"checkbox\" name=\"analyze\" /> {$lang['stranalyze']}</p>\n";
+ echo "<p><input type=\"checkbox\" name=\"analyze\"", (isset($_REQUEST['analyze']) ? ' checked="checked"' : ''), " /> {$lang['stranalyze']}</p>\n";
echo "<input type=\"submit\" name=\"cluster\" value=\"{$lang['strcluster']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
echo "</form>\n";
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.109 2003/10/06 18:10:18 soranzo Exp $
+ * $Id: english.php,v 1.110 2003/10/08 02:14:24 chriskl Exp $
*/
// Language and character set
// Info
$lang['strreferringtables'] = 'Referring Tables';
+ $lang['strparenttables'] = 'Parent Tables';
+ $lang['strchildtables'] = 'Child Tables';
// Miscellaneous
$lang['strtopbar'] = '%s running on %s:%s -- You are logged in as user "%s", %s';
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.61 2003/10/06 18:10:18 soranzo Exp $
+ * $Id: english.php,v 1.62 2003/10/08 02:14:24 chriskl Exp $
*/
// Language and character set
// Info
$lang['strreferringtables'] = 'Referring Tables';
+ $lang['strparenttables'] = 'Parent Tables';
+ $lang['strchildtables'] = 'Child Tables';
// Miscellaneous
$lang['strtopbar'] = '%s running on %s:%s -- You are logged in as user "%s", %s';