* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.311 2007/11/21 12:59:42 ioguix Exp $
+ * $Id: Postgres.php,v 1.312 2007/11/21 15:45:31 ioguix Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
}
/**
- * Alters a table
- * @param $table The name of the table
+ * Protected method which alter a table
+ * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION
+ * @param $tblrs The table recordSet returned by getTable()
* @param $name The new name for the table
* @param $owner The new owner for the table
+ * @param $schema The new schema for the table
* @param $comment The comment on the table
* @param $tablespace The new tablespace for the table ('' means leave as is)
* @return 0 success
- * @return -1 transaction error
- * @return -2 owner error
* @return -3 rename error
* @return -4 comment error
- * @return -5 get existing table error
+ * @return -5 owner error
* @return -6 tablespace error
+ * @return -7 schema error
*/
- function alterTable($table, $name, $owner, $comment, $tablespace) {
- $this->fieldClean($table);
+ /* protected */
+ function _alterTable($tblrs, $name, $owner, $schema, $comment, $tablespace) {
+
$this->fieldClean($name);
- $this->fieldClean($owner);
$this->clean($comment);
- $this->fieldClean($tablespace);
-
- $status = $this->beginTransaction();
- if ($status != 0) {
- $this->rollbackTransaction();
- return -1;
- }
-
+ /* $schema, $owner, $tablespace not supported in pg70 */
+
+ $table = $tblrs->fields['relname'];
+
// Comment
$status = $this->setComment('TABLE', '', $table, $comment);
if ($status != 0) {
return -4;
}
- // Owner
- if ($this->hasAlterTableOwner() && $owner != '') {
- // Fetch existing owner
- $data = $this->getTable($table);
- if ($data->recordCount() != 1) {
- $this->rollbackTransaction();
- return -5;
- }
-
- // If owner has been changed, then do the alteration. We are
- // careful to avoid this generally as changing owner is a
- // superuser only function.
- if ($data->fields['relowner'] != $owner) {
- $sql = "ALTER TABLE \"{$table}\" OWNER TO \"{$owner}\"";
-
- $status = $this->execute($sql);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -2;
- }
- }
- }
-
- // Tablespace
- if ($this->hasTablespaces() && $tablespace != '') {
- // Fetch existing tablespace
- $data = $this->getTable($table);
- if ($data->recordCount() != 1) {
- $this->rollbackTransaction();
- return -5;
- }
-
- // If tablespace has been changed, then do the alteration. We
- // don't want to do this unnecessarily.
- if ($data->fields['tablespace'] != $tablespace) {
- $sql = "ALTER TABLE \"{$table}\" SET TABLESPACE \"{$tablespace}\"";
-
- $status = $this->execute($sql);
- if ($status != 0) {
- $this->rollbackTransaction();
- return -6;
- }
- }
- }
-
// Rename (only if name has changed)
if ($name != $table) {
$sql = "ALTER TABLE \"{$table}\" RENAME TO \"{$name}\"";
}
}
- return $this->endTransaction();
+ return 0;
}
+ /**
+ * Alter table properties
+ * @param $table The name of the table
+ * @param $name The new name for the table
+ * @param $owner The new owner for the table
+ * @param $schema The new schema for the table
+ * @param $comment The comment on the table
+ * @param $tablespace The new tablespace for the table ('' means leave as is)
+ * @return 0 success
+ * @return -1 transaction error
+ * @return -2 get existing table error
+ * @return $this->_alterTable error code
+ */
+ function alterTable($table, $name, $owner, $schema, $comment, $tablespace) {
+
+ $this->fieldClean($table);
+ $data = $this->getTable($table);
+ if ($data->recordCount() != 1)
+ return -2;
+
+ $status = $this->beginTransaction();
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -1;
+ }
+
+ $status = $this->_alterTable($data, $name, $owner, $schema, $comment, $tablespace);
+
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return $status;
+ }
+
+ return $this->endTransaction();
+ }
+
/**
* Removes a table from the database
* @param $table The table to drop
function hasAlterTrigger() { return false; }
function hasWithoutOIDs() { return false; }
function hasAlterTableOwner() { return false; }
+ function hasAlterTableSchema() { return false; }
function hasAlterSequenceOwner() { return false; }
function hasAlterSequenceProps() { return false; }
function hasSequenceAlterSchema() { return false; }
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres71.php,v 1.78 2007/11/21 12:59:42 ioguix Exp $
+ * $Id: Postgres71.php,v 1.79 2007/11/21 15:45:31 ioguix Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
// Table functions
+ /**
+ * Protected method which alter a table
+ * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION
+ * @param $tblrs The table recordSet returned by getTable()
+ * @param $name The new name for the table
+ * @param $owner The new owner for the table
+ * @param $schema The new schema for the table
+ * @param $comment The comment on the table
+ * @param $tablespace The new tablespace for the table ('' means leave as is)
+ * @return 0 success
+ * @return -3 rename error
+ * @return -4 comment error
+ * @return -5 owner error
+ * @return -6 tablespace error
+ * @return -7 schema error
+ */
+ /* protected */
+ function _alterTable($tblrs, $name, $owner, $schema, $comment, $tablespace) {
+
+ $status = parent::_alterTable($tblrs, $name, $owner, $schema, $comment, $tablespace);
+ if ($status != 0)
+ return $status;
+
+ // if name != tablename, table has been renamed in parent
+ $tablename = ($tblrs->fields['relname'] == $name) ? $tblrs->fields['relname'] : $name;
+
+ /* $tablespace, schema not supported in pg71 */
+ $this->fieldClean($owner);
+
+ // Owner
+ if (!empty($owner) && ($tblrs->fields['relowner'] != $owner)) {
+ // If owner has been changed, then do the alteration. We are
+ // careful to avoid this generally as changing owner is a
+ // superuser only function.
+ $sql = "ALTER TABLE \"{$tablename}\" OWNER TO \"{$owner}\"";
+
+ $status = $this->execute($sql);
+ if ($status != 0) return -5;
+ }
+
+ return 0;
+ }
+
/**
* Finds the number of rows that would be returned by a
* query.
/* $schema, $increment, $minvalue, $maxvalue, $startvalue, $cachevalue,
* $cycledvalue not supported in pg71 */
// if name != seqname, sequence has been renamed in parent
- $sequence = ($seqrs->fields['seqname'] = $name) ? $seqrs->fields['seqname'] : $name;
+ $sequence = ($seqrs->fields['seqname'] == $name) ? $seqrs->fields['seqname'] : $name;
$this->fieldClean($owner);
// Owner
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres74.php,v 1.67 2007/11/21 12:59:42 ioguix Exp $
+ * $Id: Postgres74.php,v 1.68 2007/11/21 15:45:31 ioguix Exp $
*/
include_once('./classes/database/Postgres73.php');
/* $schema not supported in pg74 */
// if name != seqname, sequence has been renamed in parent
- $sequence = ($seqrs->fields['seqname'] = $name) ? $seqrs->fields['seqname'] : $name;
+ $sequence = ($seqrs->fields['seqname'] == $name) ? $seqrs->fields['seqname'] : $name;
$this->clean($increment);
$this->clean($minvalue);
$this->clean($maxvalue);
/**
* PostgreSQL 8.0 support
*
- * $Id: Postgres80.php,v 1.26 2007/11/16 18:34:24 ioguix Exp $
+ * $Id: Postgres80.php,v 1.27 2007/11/21 15:45:31 ioguix Exp $
*/
include_once('./classes/database/Postgres74.php');
$sql = "
SELECT
- c.relname, u.usename AS relowner,
+ c.relname, n.nspname, u.usename AS relowner,
pg_catalog.obj_description(c.oid, 'pg_class') AS relcomment,
(SELECT spcname FROM pg_catalog.pg_tablespace pt WHERE pt.oid=c.reltablespace) AS tablespace
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind = 'r'
AND n.nspname = '{$this->_schema}'
+ AND n.oid = c.relnamespace
AND c.relname = '{$table}'";
return $this->selectSet($sql);
}
+
+ /**
+ * Protected method which alter a table
+ * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION
+ * @param $tblrs The table recordSet returned by getTable()
+ * @param $name The new name for the table
+ * @param $owner The new owner for the table
+ * @param $schema The new schema for the table
+ * @param $comment The comment on the table
+ * @param $tablespace The new tablespace for the table ('' means leave as is)
+ * @return 0 success
+ * @return -3 rename error
+ * @return -4 comment error
+ * @return -5 owner error
+ * @return -6 tablespace error
+ * @return -7 schema error
+ */
+ /* protected */
+ function _alterTable($tblrs, $name, $owner, $schema, $comment, $tablespace) {
+
+ $status = parent::_alterTable($tblrs, $name, $owner, $schema, $comment, $tablespace);
+ if ($status != 0)
+ return $status;
+
+ // if name != tablename, table has been renamed in parent
+ $tablename = ($tblrs->fields['relname'] == $name) ? $tblrs->fields['relname'] : $name;
+
+ /* $schema not supported in pg80 */
+ $this->fieldClean($tablespace);
+
+ // Tablespace
+ if (!empty($tablespace) && ($tblrs->fields['tablespace'] != $tablespace)) {
+
+ // If tablespace has been changed, then do the alteration. We
+ // don't want to do this unnecessarily.
+ $sql = "ALTER TABLE \"{$tablename}\" SET TABLESPACE \"{$tablespace}\"";
+
+ $status = $this->execute($sql);
+ if ($status != 0) return -6;
+ }
+
+ return 0;
+ }
/**
* Alters a column in a table
function hasTablespaces() { return true; }
function hasSignals() { return true; }
function hasNamedParams() { return true; }
- function hasFunctionAlterOwner() { return true; }
+ function hasFunctionAlterOwner() { return true; }
}
-
?>
/**
* PostgreSQL 8.1 support
*
- * $Id: Postgres81.php,v 1.16 2007/11/21 12:59:42 ioguix Exp $
+ * $Id: Postgres81.php,v 1.17 2007/11/21 15:45:31 ioguix Exp $
*/
include_once('./classes/database/Postgres80.php');
// Table methods
+ /**
+ * Protected method which alter a table
+ * SHOULDN'T BE CALLED OUTSIDE OF A TRANSACTION
+ * @param $tblrs The table recordSet returned by getTable()
+ * @param $name The new name for the table
+ * @param $owner The new owner for the table
+ * @param $schema The new schema for the table
+ * @param $comment The comment on the table
+ * @param $tablespace The new tablespace for the table ('' means leave as is)
+ * @return 0 success
+ * @return -3 rename error
+ * @return -4 comment error
+ * @return -5 owner error
+ * @return -6 tablespace error
+ * @return -7 schema error
+ */
+ /* protected */
+ function _alterTable($tblrs, $name, $owner, $schema, $comment, $tablespace) {
+
+ $status = parent::_alterTable($tblrs, $name, $owner, $schema, $comment, $tablespace);
+ if ($status != 0)
+ return $status;
+
+ // if name != tablename, table has been renamed in parent
+ $tablename = ($tblrs->fields['relname'] == $name) ? $tblrs->fields['relname'] : $name;
+
+ $this->fieldClean($schema);
+
+ // Schema
+ if (!empty($schema) && ($tblrs->fields['nspname'] != $schema)) {
+
+ // If tablespace has been changed, then do the alteration. We
+ // don't want to do this unnecessarily.
+ $sql = "ALTER TABLE \"{$tablename}\" SET SCHEMA \"{$schema}\"";
+
+ $status = $this->execute($sql);
+ if ($status != 0) return -7;
+ }
+
+ return 0;
+ }
+
/**
* Enables a trigger
* @param $tgname The name of the trigger to enable
return $status;
// if name != seqname, sequence has been renamed in parent
- $sequence = ($seqrs->fields['seqname'] = $name) ? $seqrs->fields['seqname'] : $name;
+ $sequence = ($seqrs->fields['seqname'] == $name) ? $seqrs->fields['seqname'] : $name;
$this->clean($schema);
if ($seqrs->fields['nspname'] != $schema) {
function hasPreparedXacts() { return true; }
function hasDisableTriggers() { return true; }
function hasFunctionAlterSchema() { return true; }
+ function hasAlterTableSchema() { return true; }
function hasSequenceAlterSchema() { return true; }
}
/**
* List tables in a database
*
- * $Id: tblproperties.php,v 1.88 2007/10/19 08:59:22 ioguix Exp $
+ * $Id: tblproperties.php,v 1.89 2007/11/21 15:45:31 ioguix Exp $
*/
// Include application functions
* Function to save after altering a table
*/
function doSaveAlter() {
- global $data, $lang, $_reload_browser;
+ global $data, $lang, $_reload_browser, $misc;
// For databases that don't allow owner change
if (!isset($_POST['owner'])) $_POST['owner'] = '';
// Default tablespace to null if it isn't set
if (!isset($_POST['tablespace'])) $_POST['tablespace'] = null;
+ if (!isset($_POST['newschema'])) $_POST['newschema'] = null;
- $status = $data->alterTable($_POST['table'], $_POST['name'], $_POST['owner'], $_POST['comment'], $_POST['tablespace']);
+ $status = $data->alterTable($_POST['table'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment'], $_POST['tablespace']);
if ($status == 0) {
// If table has been renamed, need to change to the new name and
// reload the browser frame.
// Force a browser reload
$_reload_browser = true;
}
+ // If schema has changed, need to change to the new schema and reload the browser
+ if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) {
+ // Jump them to the new sequence schema
+ $misc->setCurrentSchema($_POST['newschema']);
+ $_reload_browser = true;
+ }
doDefault($lang['strtablealtered']);
}
else
if (!isset($_POST['name'])) $_POST['name'] = $table->fields['relname'];
if (!isset($_POST['owner'])) $_POST['owner'] = $table->fields['relowner'];
+ if (!isset($_POST['newschema'])) $_POST['newschema'] = $table->fields['nspname'];
if (!isset($_POST['comment'])) $_POST['comment'] = $table->fields['relcomment'];
if ($data->hasTablespaces() && !isset($_POST['tablespace'])) $_POST['tablespace'] = $table->fields['tablespace'];
}
echo "</select></td></tr>\n";
}
-
+
+ if ($data->hasAlterTableSchema()) {
+ $schemas = $data->getSchemas();
+ echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n";
+ echo "<td class=\"data1\"><select name=\"newschema\">";
+ while (!$schemas->EOF) {
+ $schema = $schemas->fields['nspname'];
+ echo "<option value=\"", htmlspecialchars($schema), "\"",
+ ($schema == $_POST['newschema']) ? ' selected="selected"' : '', ">", htmlspecialchars($schema), "</option>\n";
+ $schemas->moveNext();
+ }
+ echo "</select></td></tr>\n";
+ }
+
// Tablespace (if there are any)
if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n";