* Allow browsers to save different usernames and passwords for different servers.
* Pagination selection available for reports
* You can configure reports db, schema and table names
+* Add support for creating a table using an exsting one (ioguix)
Bugs
* Fix inability to assign a field type/domain of a different schema
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.299 2007/07/20 04:38:34 xzilla Exp $
+ * $Id: Postgres.php,v 1.300 2007/08/31 19:46:23 ioguix Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
}
return $this->endTransaction();
- }
+ }
/**
* Alters a table
function hasAlterAggregate() { return false; }
function hasSharedComments() {return false;}
function hasAnalyze() {return false;}
+ function hasCreateTableLike() {return false;}
+ function hasCreateTableLikeWithConstraints() {return false;}
}
?>
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres74.php,v 1.58 2007/08/31 18:30:11 ioguix Exp $
+ * $Id: Postgres74.php,v 1.59 2007/08/31 19:46:24 ioguix Exp $
*/
include_once('./classes/database/Postgres73.php');
}
}
+ /**
+ * Creates a new table in the database copying attribs and other properties from another table
+ * @param $name The name of the table
+ * @param $like The name of the table from which attribs are copying from
+ * @param $defaults if true, copy the defaults values as well
+ * @param $constraints if true, copy the constraints as well (CHECK on table & attr)
+ * @param $tablespace The tablespace name ('' means none/default)
+ */
+ function createTableLike($name, $like, $defaults = false, $constraints = false, $tablespace = '') {
+ $this->fieldClean($name);
+ $this->fieldClean($like);
+
+ $status = $this->beginTransaction();
+ if ($status != 0) return -1;
+
+ $sql = "CREATE TABLE \"{$name}\" (LIKE {$like}";
+
+ if ($defaults) $sql .= " INCLUDING DEFAULTS";
+ if ($this->hasCreateTableLikeWithConstraints() && $constraints) $sql .= " INCLUDING CONSTRAINTS";
+
+ $sql .= ")";
+
+ if ($this->hasTablespaces() && $tablespace != '') {
+ $this->fieldClean($tablespace);
+ $sql .= " TABLESPACE \"{$tablespace}\"";
+ }
+
+ $status = $this->execute($sql);
+ if ($status) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ return $this->endTransaction();
+ }
+
// Group functions
/**
function hasReadOnlyQueries() { return true; }
function hasAlterSequence() { return true; }
function hasAlterAggregate() { return true; }
+ function hasCreateTableLike() { return true; }
}
?>
/**
* PostgreSQL 8.2 support
*
- * $Id: Postgres82.php,v 1.5 2007/03/28 18:52:34 soranzo Exp $
+ * $Id: Postgres82.php,v 1.6 2007/08/31 19:46:24 ioguix Exp $
*/
include_once('./classes/database/Postgres81.php');
// Capabilities
function hasSharedComments() {return true;}
+ function hasCreateTableLikeWithConstraints() {return true;}
}
?>
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.213 2007/07/19 03:11:52 xzilla Exp $
+ * $Id: english.php,v 1.214 2007/08/31 19:46:24 ioguix Exp $
*/
// Language and character set
$lang['strnotables'] = 'No tables found.';
$lang['strnotable'] = 'No table found.';
$lang['strcreatetable'] = 'Create table';
+ $lang['strcreatetablelike'] = 'Create table like';
+ $lang['strcreatetablelikeparent'] = 'Source table';
+ $lang['strcreatelikewithdefaults'] = 'INCLUDE DEFAULTS';
+ $lang['strcreatelikewithconstraints'] = 'INCLUDE CONSTRAINTS';
$lang['strtablename'] = 'Table name';
$lang['strtableneedsname'] = 'You must give a name for your table.';
+ $lang['strtablelikeneedslike'] = 'You must give a table to copy properties from.';
$lang['strtableneedsfield'] = 'You must specify at least one field.';
$lang['strtableneedscols'] = 'You must specify a valid number of columns.';
$lang['strtablecreated'] = 'Table created.';
* French Language file for phpPgAdmin.
* @maintainer Pascal PEYRE [pascal.peyre@cir.fr]
*
- * $Id: french.php,v 1.27 2007/07/19 03:11:52 xzilla Exp $
+ * $Id: french.php,v 1.28 2007/08/31 19:46:24 ioguix Exp $
*/
// Language and character set
$lang['strnotables'] = 'Aucune table trouvée.';
$lang['strnotable'] = 'Aucune table trouvée.';
$lang['strcreatetable'] = 'Créer une table';
+ $lang['strcreatetablelike'] = 'Créer une table d\'après une table existante';
+ $lang['strcreatetablelikeparent'] = 'Table modèle';
+ $lang['strcreatelikewithdefaults'] = 'INCLUDE DEFAULTS';
+ $lang['strcreatelikewithconstraints'] = 'INCLUDE CONSTRAINTS';
$lang['strtablename'] = 'Nom de la table';
$lang['strtableneedsname'] = 'Vous devez donner un nom pour votre table.';
+ $lang['strtablelikeneedslike'] = 'Vous devez préciser une table modèle.';
$lang['strtableneedsfield'] = 'Vous devez spécifier au moins un champ.';
$lang['strtableneedscols'] = 'Vous devez indiquer un nombre valide de colonnes.';
$lang['strtablecreated'] = 'Table créée.';
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.165 2007/07/19 03:11:52 xzilla Exp $
+ * $Id: english.php,v 1.166 2007/08/31 19:46:24 ioguix Exp $
*/
// Language and character set
$lang['strnotables'] = 'No tables found.';
$lang['strnotable'] = 'No table found.';
$lang['strcreatetable'] = 'Create table';
+ $lang['strcreatetablelike'] = 'Create table like';
+ $lang['strcreatetablelikeparent'] = 'Source table';
+ $lang['strcreatelikewithdefaults'] = 'INCLUDE DEFAULTS';
+ $lang['strcreatelikewithconstraints'] = 'INCLUDE CONSTRAINTS';
$lang['strtablename'] = 'Table name';
$lang['strtableneedsname'] = 'You must give a name for your table.';
+ $lang['strtablelikeneedslike'] = 'You must give a table to copy properties from.';
$lang['strtableneedsfield'] = 'You must specify at least one field.';
$lang['strtableneedscols'] = 'You must specify a valid number of columns.';
$lang['strtablecreated'] = 'Table created.';
* French Language file for phpPgAdmin.
* @maintainer Pascal PEYRE [pascal.peyre@cir.fr]
*
- * $Id: french.php,v 1.26 2007/07/19 03:11:52 xzilla Exp $
+ * $Id: french.php,v 1.27 2007/08/31 19:46:24 ioguix Exp $
*/
// Language and character set
$lang['strnotables'] = 'Aucune table trouvée.';
$lang['strnotable'] = 'Aucune table trouvée.';
$lang['strcreatetable'] = 'Créer une table';
+ $lang['strcreatetablelike'] = 'Créer une table d\'après une table existante';
+ $lang['strcreatetablelikeparent'] = 'Table modèle';
+ $lang['strcreatelikewithdefaults'] = 'INCLUDE DEFAULTS';
+ $lang['strcreatelikewithconstraints'] = 'INCLUDE CONSTRAINTS';
$lang['strtablename'] = 'Nom de la table';
$lang['strtableneedsname'] = 'Vous devez donner un nom pour votre table.';
+ $lang['strtablelikeneedslike'] = 'Vous devez préciser une table modèle.';
$lang['strtableneedsfield'] = 'Vous devez spécifier au moins un champ.';
$lang['strtableneedscols'] = 'Vous devez indiquer un nombre valide de colonnes.';
$lang['strtablecreated'] = 'Table créée.';
/**
* List tables in a database
*
- * $Id: tables.php,v 1.101 2007/08/31 18:30:11 ioguix Exp $
+ * $Id: tables.php,v 1.102 2007/08/31 19:46:23 ioguix Exp $
*/
// Include application functions
}
}
+ /**
+ * Dsiplay a screen where user can create a table from an existing one.
+ */
+ function doCreateLike($confirm, $msg = '') {
+ global $data, $misc, $lang;
+
+ if (!$confirm) {
+
+ include_once('./classes/Gui.php');
+
+ if (!isset($_REQUEST['name'])) $_REQUEST['name'] = '';
+ if (!isset($_REQUEST['like'])) $_REQUEST['like'] = '';
+ if (!isset($_REQUEST['tablespace'])) $_REQUEST['tablespace'] = '';
+
+ $misc->printTrail('schema');
+ $misc->printTitle($lang['strcreatetable'], 'pg.table.create');
+ $misc->printMsg($msg);
+
+ $tbltmp = $data->getTables(true);
+ $tbltmp = $tbltmp->getArray();
+
+ $tables = array();
+ if ( $data->hasSchemas() )
+ foreach ($tbltmp as $a) $tables["{$a['nspname']}.{$a['relname']}"] = "{$a['nspname']}.{$a['relname']}";
+ else
+ foreach ($tbltmp as $a) $tables[$a['relname']] = $a['relname'];
+
+ unset($tbltmp);
+
+ echo "<form action=\"tables.php\" method=\"post\">\n";
+ echo "<table>\n\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
+ echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n";
+ echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strcreatetablelikeparent']}</th>\n";
+ echo "\t\t<td class=\"data\">";
+ echo GUI::printCombo($tables, 'like', true, $_REQUEST['like'], false);
+ echo "</td>\n\t</tr>\n";
+ if ($data->hasTablespaces()) {
+ $tblsp_ = $data->getTablespaces();
+ if ($tblsp_->recordCount() > 0) {
+ $tblsp_ = $tblsp_->getArray();
+ $tblsp = array();
+ foreach($tblsp_ as $a) $tblsp[$a['spcname']] = $a['spcname'];
+
+ echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n";
+ echo "\t\t<td class=\"data\">";
+ echo GUI::printCombo($tblsp, 'tablespace', true, $_REQUEST['tablespace'], false);
+ echo "</td>\n\t</tr>\n";
+ }
+ }
+ echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['stroptions']}</th>\n\t\t<td class=\"data\">";
+ echo "<label for=\"withdefaults\"><input type=\"checkbox\" id=\"withdefaults\" name=\"withdefaults\"",
+ isset($_REQUEST['withdefaults']) ? ' checked="checked"' : '',
+ "/>{$lang['strcreatelikewithdefaults']}</label>";
+ if ($data->hasCreateTableLikeWithConstraints()) {
+ echo "<label for=\"withconstraints\"><input type=\"checkbox\" id=\"withconstraints\" name=\"withconstraints\"",
+ isset($_REQUEST['withconstraints']) ? ' checked="checked"' : '',
+ "/>{$lang['strcreatelikewithconstraints']}</label>";
+ }
+ echo "</td>\n\t</tr>\n";
+ echo "</table>";
+
+ echo "<input type=\"hidden\" name=\"action\" value=\"confcreatelike\" />\n";
+ echo $misc->form;
+ echo "<p><input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
+ echo "</form>\n";
+ }
+ else {
+ global $_reload_browser;
+
+ if (trim($_REQUEST['name']) == '') {
+ doCreateLike(false, $lang['strtableneedsname']);
+ return;
+ }
+ if (trim($_REQUEST['like']) == '') {
+ doCreateLike(false, $lang['strtablelikeneedslike']);
+ return;
+ }
+
+ $status = $data->createTableLike($_REQUEST['name'], $_REQUEST['like'], isset($_REQUEST['withdefaults']), isset($_REQUEST['withconstraints']), $_REQUEST['tablespace']);
+ if ($status == 0) {
+ $_reload_browser = true;
+ doDefault($lang['strtablecreated']);
+ }
+ else {
+ doCreateLike(false, $lang['strtablecreatedbad']);
+ return;
+ }
+ }
+ }
+
/**
* Ask for select parameters and perform select
*/
$misc->printTable($tables, $columns, $actions, $lang['strnotables']);
- echo "<p><a class=\"navlink\" href=\"tables.php?action=create&{$misc->href}\">{$lang['strcreatetable']}</a></p>\n";
+ echo "<p><a class=\"navlink\" href=\"tables.php?action=create&{$misc->href}\">{$lang['strcreatetable']}</a> |\n";
+ if ($data->hasCreateTableLike())
+ echo "<a class=\"navlink\" href=\"tables.php?action=createlike&{$misc->href}\">{$lang['strcreatetablelike']}</a>\n";
+ echo "</p>\n";
}
/**
if (isset($_POST['cancel'])) doDefault();
else doCreate();
break;
+ case 'createlike':
+ doCreateLike(false);
+ break;
+ case 'confcreatelike':
+ if (isset($_POST['cancel'])) doDefault();
+ else doCreateLike(true);
+ break;
case 'selectrows':
if (!isset($_POST['cancel'])) doSelectRows(false);
else doDefault();