* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.261.2.2 2005/06/09 15:01:02 chriskl Exp $
+ * $Id: Postgres.php,v 1.261.2.3 2005/06/16 14:12:48 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
/**
* Grabs a list of indexes for a table
* @param $table The name of a table whose indexes to retrieve
+ * @param $unique Only get unique/pk indexes
* @return A recordset
*/
- function &getIndexes($table = '') {
+ function &getIndexes($table = '', $unique = false) {
$this->clean($table);
$sql = "SELECT c2.relname AS indname, i.indisprimary, i.indisunique, pg_get_indexdef(i.indexrelid) AS inddef
FROM pg_class c, pg_class c2, pg_index i
WHERE c.relname = '{$table}' AND c.oid = i.indrelid AND i.indexrelid = c2.oid
- ORDER BY c2.relname";
+ ";
+ if ($unique) $sql .= " AND i.indisunique ";
+ $sql .= " ORDER BY c2.relname";
return $this->selectSet($sql);
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.143.2.1 2005/06/09 15:01:05 chriskl Exp $
+ * $Id: Postgres73.php,v 1.143.2.2 2005/06/16 14:12:49 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
/**
* Grabs a list of indexes for a table
* @param $table The name of a table whose indexes to retrieve
+ * @param $unique Only get unique/pk indexes
* @return A recordset
*/
- function &getIndexes($table = '') {
+ function &getIndexes($table = '', $unique = false) {
$this->clean($table);
$sql = "SELECT c2.relname AS indname, i.indisprimary, i.indisunique, i.indisclustered,
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
- ORDER BY c2.relname";
+ ";
+ if ($unique) $sql .= " AND i.indisunique ";
+ $sql .= " ORDER BY c2.relname";
return $this->selectSet($sql);
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres74.php,v 1.44 2005/04/30 18:02:01 soranzo Exp $
+ * $Id: Postgres74.php,v 1.44.2.1 2005/06/16 14:12:49 chriskl Exp $
*/
include_once('./classes/database/Postgres73.php');
/**
* Grabs a list of indexes for a table
* @param $table The name of a table whose indexes to retrieve
+ * @param $unique Only get unique/pk indexes
* @return A recordset
*/
- function &getIndexes($table = '') {
+ function &getIndexes($table = '', $unique = false) {
$this->clean($table);
$sql = "SELECT c2.relname AS indname, i.indisprimary, i.indisunique, i.indisclustered,
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
- ORDER BY c2.relname";
+ ";
+ if ($unique) $sql .= " AND i.indisunique ";
+ $sql .= " ORDER BY c2.relname";
return $this->selectSet($sql);
}
/**
* A class that implements the Slony 1.0.x support plugin
*
- * $Id: Slony.php,v 1.1.2.23 2005/06/15 14:32:58 chriskl Exp $
+ * $Id: Slony.php,v 1.1.2.24 2005/06/16 14:12:49 chriskl Exp $
*/
include_once('./classes/plugins/Plugin.php');
/**
* Adds a table to a replication set
*/
- function addTable($set_id, $tab_id, $fqname, $idxname, $comment, $addtablekey) {
+ function addTable($set_id, $tab_id, $nspname, $relname, $idxname, $comment, $storedtriggers) {
global $data;
$schema = $this->slony_schema;
$data->fieldClean($schema);
$data->clean($set_id);
$data->clean($tab_id);
+ $fqname = $nspname . '.' . $relname;
$data->clean($fqname);
+ $data->clean($nspname);
+ $data->clean($relname);
$data->clean($idxname);
$data->clean($comment);
- if ($addtablekey) {
+ $hastriggers = (sizeof($storedtriggers) > 0);
+ if ($hastriggers) {
// Begin a transaction
$status = $data->beginTransaction();
if ($status != 0) return -1;
-
- // Add the table key
- $sql = "SELECT \"{$schema}\".tableaddkey('{$fqname}')";
- $status = $data->execute($sql);
- if ($status != 0) {
- $data->rollbackTransaction();
- return -2;
- }
}
if ($tab_id != '')
$sql = "SELECT \"{$schema}\".setaddtable('{$set_id}', '{$tab_id}', '{$fqname}', '{$idxname}', '{$comment}')";
- else
- $sql = "SELECT \"{$schema}\".setaddtable('{$set_id}', (SELECT COALESCE(MAX(tab_id), 0) + 1 FROM \"{$schema}\".sl_table), '{$fqname}', '{$idxname}', '{$comment}')";
+ else {
+ $sql = "SELECT \"{$schema}\".setaddtable('{$set_id}', (SELECT COALESCE(MAX(tab_id), 0) + 1 FROM \"{$schema}\".sl_table), '{$fqname}', '{$idxname}', '{$comment}')";
+ }
$status = $data->execute($sql);
-
- if ($status != 0 && $addtablekey) {
- $data->rollbackTransaction();
+ if ($status != 0) {
+ if ($hastriggers) $data->rollbackTransaction();
return -3;
+ }
+
+ // If we are storing triggers, we need to know the tab_id that was assigned to the table
+ if ($tab_id == '' && $hastriggers) {
+ $sql = "SELECT tab_id
+ FROM \"{$schema}\".sl_table
+ WHERE tab_set='{$set_id}'
+ AND tab_reloid=(SELECT pc.oid FROM pg_catalog.pg_class pc, pg_namespace pn
+ WHERE pc.relnamespace=pn.oid AND pc.relname='{$relname}'
+ AND pn.nspname='{$nspname}')";
+ $tab_id = $data->selectField($sql, 'tab_id');
+ if ($tab_id === -1) {
+ $data->rollbackTransaction();
+ return -4;
+ }
}
- return $status;
+ // Store requested triggers
+ if ($hastriggers) {
+ foreach ($storedtriggers as $tgname) {
+ $data->clean($tgname);
+ $sql = "SELECT \"{$schema}\".storetrigger('{$tab_id}', '{$tgname}')";
+ $status = $data->execute($sql);
+ if ($status != 0) {
+ $data->rollbackTransaction();
+ return -5;
+ }
+ }
+ }
+
+ if ($hastriggers)
+ return $data->endTransaction();
+ else
+ return $status;
}
/**
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.176.2.6 2005/06/15 19:05:10 soranzo Exp $
+ * $Id: english.php,v 1.176.2.7 2005/06/16 14:12:49 chriskl Exp $
*/
// Language and character set
$lang['strscriptneedsbody'] = 'You must supply a script to be executed on all nodes.';
$lang['strscriptexecuted'] = 'Replication set DDL script executed.';
$lang['strscriptexecutedbad'] = 'Failed executing replication set DDL script.';
+ $lang['strtabletriggerstoretain'] = 'The following triggers will NOT be disabled by Slony:';
// Slony tables in replication sets
$lang['straddtable'] = 'Add table';
* English language file for phpPgAdmin. Use this as a basis
* for new translations.
*
- * $Id: english.php,v 1.128.2.7 2005/06/15 19:05:11 soranzo Exp $
+ * $Id: english.php,v 1.128.2.8 2005/06/16 14:12:49 chriskl Exp $
*/
// Language and character set
$lang['strscriptneedsbody'] = 'You must supply a script to be executed on all nodes.';
$lang['strscriptexecuted'] = 'Replication set DDL script executed.';
$lang['strscriptexecutedbad'] = 'Failed executing replication set DDL script.';
+ $lang['strtabletriggerstoretain'] = 'The following triggers will NOT be disabled by Slony:';
// Slony tables in replication sets
$lang['straddtable'] = 'Add table';
/**
* Slony database tab plugin
*
- * $Id: plugin_slony.php,v 1.1.2.24 2005/06/15 19:05:09 soranzo Exp $
+ * $Id: plugin_slony.php,v 1.1.2.25 2005/06/16 14:12:47 chriskl Exp $
*/
// Include application functions
$key = array('schemaname' => $tables->f['nspname'], 'tablename' => $tables->f['relname']);
$key = serialize($key);
echo "<option value=\"", htmlspecialchars($key), "\">";
- if ($data->hasSchemas()) {
- echo htmlspecialchars($tables->f['nspname']), '.';
- }
+ echo htmlspecialchars($tables->f['nspname']), '.';
echo htmlspecialchars($tables->f['relname']), "</option>\n";
$tables->moveNext();
}
htmlspecialchars($_POST['comment']), "</textarea></td>\n\t</tr>\n";
echo "\t</tr>\n";
- echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['stradduniq']}</th>\n";
- echo "\t\t<td class=\"data\"><input type=\"checkbox\" name=\"addtablekey\"",
- (isset($_REQUEST['addtablekey']) ? ' checked="checked"' : ''), " /></td>\n\t</tr>\n";
echo "</table>\n";
echo "<p>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"add_table\" />\n";
// Unserialize table and fetch. This is a bit messy
// because the table could be in another schema.
$_REQUEST['target'] = unserialize($_REQUEST['target']);
- if ($data->hasSchemas())
- $data->setSchema($_REQUEST['target']['schemaname']);
- $indexes = &$data->getIndexes($_REQUEST['target']['tablename']);
+ $data->setSchema($_REQUEST['target']['schemaname']);
+ // Get indexes
+ $indexes = &$data->getIndexes($_REQUEST['target']['tablename'], true);
if ($indexes->recordCount() == 0) {
- doTables($lang['strtableneedsuniquekey']);
- return;
+ doAddTable(1, $lang['strtableneedsuniquekey']);
+ return;
+ }
+
+ // Get triggers
+ $triggers = &$data->getTriggers($_REQUEST['target']['tablename']);
+
+ // If only one index and no triggers then jump to next step
+ if ($indexes->recordCount() == 1 && $triggers->recordCount() == 0) {
+ $_REQUEST['idxname'] = $indexes->f['indname'];
+ $_REQUEST['nspname'] = $_REQUEST['target']['schemaname'];
+ $_REQUEST['relname'] = $_REQUEST['target']['tablename'];
+ $_REQUEST['target'] = serialize($_REQUEST['target']);
+ doAddTable(3);
+ return;
}
$misc->printTrail('slony_sets');
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo $misc->form;
echo "<table>\n";
- echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strindex']}</th>\n";
- echo "<td class=\"data1\" colspan=\"3\"><select name=\"idxname\">";
- while (!$indexes->EOF) {
- echo "<option value=\"", htmlspecialchars($indexes->f['indname']), "\">";
- echo htmlspecialchars($indexes->f['indname']), "</option>\n";
- $indexes->moveNext();
+ if ($indexes->recordCount() > 1) {
+ echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strindex']}</th>\n";
+ echo "<td class=\"data1\" colspan=\"3\"><select name=\"idxname\">";
+ while (!$indexes->EOF) {
+ echo "<option value=\"", htmlspecialchars($indexes->f['indname']), "\">";
+ echo htmlspecialchars($indexes->f['indname']), "</option>\n";
+ $indexes->moveNext();
+ }
+ echo "</select></td></tr>\n";
+ }
+ else {
+ echo "<input type=\"hidden\" name=\"idxname\" value=\"", htmlspecialchars($indexes->f['indname']), "\" />\n";
+ }
+ if ($triggers->recordCount() > 0) {
+ echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strtriggers']}</th>\n";
+ echo "<td class=\"data1\" colspan=\"3\"><p>{$lang['strtabletriggerstoretain']}</p>\n";
+ while (!$triggers->EOF) {
+ echo "<input type=\"checkbox\" name=\"storedtriggers[", htmlspecialchars($triggers->f['tgname']), "]\">";
+ echo htmlspecialchars($triggers->f['tgname']), "<br/>\n";
+ $triggers->moveNext();
+ }
+ echo "</select></td></tr>\n";
}
- echo "</select></td></tr>\n";
- echo "\t</tr>\n";
echo "</table>\n";
echo "<p>\n";
echo "<input type=\"hidden\" name=\"action\" value=\"add_table\" />\n";
echo "<input type=\"hidden\" name=\"set_id\" value=\"", htmlspecialchars($_REQUEST['set_id']), "\" />\n";
echo "<input type=\"hidden\" name=\"tab_id\" value=\"", htmlspecialchars($_REQUEST['tab_id']), "\" />\n";
echo "<input type=\"hidden\" name=\"comment\" value=\"", htmlspecialchars($_REQUEST['comment']), "\" />\n";
- if (isset($_REQUEST['addtablekey'])) {
- echo "<input type=\"hidden\" name=\"addtablekey\" value=\"on\" />\n";
- }
- echo "<input type=\"hidden\" name=\"fqname\" value=\"", htmlspecialchars($_REQUEST['target']['schemaname']),
- '.', htmlspecialchars($_REQUEST['target']['tablename']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"nspname\" value=\"", htmlspecialchars($_REQUEST['target']['schemaname']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"relname\" value=\"", htmlspecialchars($_REQUEST['target']['tablename']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"target\" value=\"", htmlspecialchars(serialize($_REQUEST['target'])), "\" />\n";
echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n";
echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
echo "</form>\n";
break;
case 3:
- $status = $slony->addTable($_REQUEST['set_id'], $_REQUEST['tab_id'], $_REQUEST['fqname'],
- $_REQUEST['idxname'], $_REQUEST['comment'], isset($_REQUEST['addtablekey']));
+ if (!isset($_REQUEST['storedtriggers'])) $_REQUEST['storedtriggers'] = array();
+ $status = $slony->addTable($_REQUEST['set_id'], $_REQUEST['tab_id'], $_REQUEST['nspname'], $_REQUEST['relname'],
+ $_REQUEST['idxname'], $_REQUEST['comment'], array_keys($_REQUEST['storedtriggers']));
if ($status == 0)
doTables($lang['strtableaddedtorepset']);
else
- doAddTable(1, $lang['strtableaddedtorepsetbad']);
+ doAddTable(2, $lang['strtableaddedtorepsetbad']);
break;
}
}
$key = array('schemaname' => $sequences->f['nspname'], 'sequencename' => $sequences->f['seqname']);
$key = serialize($key);
echo "<option value=\"", htmlspecialchars($key), "\">";
- if ($data->hasSchemas()) {
- echo htmlspecialchars($sequences->f['nspname']), '.';
- }
+ echo htmlspecialchars($sequences->f['nspname']), '.';
echo htmlspecialchars($sequences->f['seqname']), "</option>\n";
$sequences->moveNext();
}