* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.44 2003/01/18 09:07:50 chriskl Exp $
+ * $Id: Postgres.php,v 1.45 2003/01/19 02:47:25 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
return $this->execute($sql);
}
+ // Trigger functions
+
+ /**
+ * Grabs a list of triggers on a table
+ * @param $table The name of a table whose triggers to retrieve
+ * @return A recordset
+ */
+ function &getTriggers($table = '') {
+ $this->clean($table);
+
+ $sql = "SELECT tgname
+ FROM pg_trigger
+ WHERE tgrelid = (SELECT oid FROM pg_class WHERE relname='{$table}')
+ AND NOT tgisconstraint";
+
+ return $this->selectSet($sql);
+ }
+
+ /**
+ * Drops a trigger
+ * @param $tgname The name of the trigger to drop
+ * @param $table The table from which to drop the trigger
+ * @return 0 success
+ */
+ function dropTrigger($tgname, $table) {
+ $this->fieldClean($tgname);
+ $this->fieldClean($table);
+
+ $sql = "DROP TRIGGER \"{$tgname}\" ON \"{$table}\"";
+
+ return $this->execute($sql);
+ }
+
// Capabilities
function hasTables() { return true; }
function hasViews() { return true; }
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.17 2003/01/18 06:38:37 chriskl Exp $
+ * $Id: Postgres73.php,v 1.18 2003/01/19 02:47:25 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
$sql = "SELECT c2.relname, i.indisprimary, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid) 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 c.oid = i.indrelid AND i.indexrelid = c2.oid
+ WHERE c.relname = '{$table}' AND pg_catalog.pg_table_is_visible(c.oid)
+ AND c.oid = i.indrelid AND i.indexrelid = c2.oid
AND NOT i.indisprimary
ORDER BY i.indisunique DESC, c2.relname";
*/
function &getTriggers($table = '') {
$this->clean($table);
-
+
$sql = "SELECT t.tgname
FROM pg_catalog.pg_trigger t
- WHERE t.tgrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}') and (not tgisconstraint OR NOT EXISTS
- (SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c
- ON (d.refclassid = c.tableoid AND d.refobjid = c.oid)
+ WHERE t.tgrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}'
+ AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{$this->_schema}'))
+ AND (NOT tgisconstraint OR NOT EXISTS
+ (SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c
+ ON (d.refclassid = c.tableoid AND d.refobjid = c.oid)
WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))";
-
+
return $this->selectSet($sql);
}
--- /dev/null
+<?php
+
+ /**
+ * List triggers on a table
+ *
+ * $Id: triggers.php,v 1.1 2003/01/19 02:47:25 chriskl Exp $
+ */
+
+ // Include application functions
+ include_once('conf/config.inc.php');
+
+ $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
+ $PHP_SELF = $_SERVER['PHP_SELF'];
+
+ /**
+ * Show confirmation of drop and perform actual drop
+ */
+ function doDrop($confirm) {
+ global $localData, $misc;
+ global $PHP_SELF, $strDrop, $strConfDropTrigger, $strTriggerDropped, $strTriggerDroppedBad, $strYes, $strNo;
+
+ if ($confirm) {
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ",
+ htmlspecialchars($_REQUEST['table']), ": " , htmlspecialchars($_REQUEST['trigger']), ": {$strDrop}</h2>\n";
+
+ echo "<p>", sprintf($strConfDropTrigger, htmlspecialchars($_REQUEST['trigger']),
+ htmlspecialchars($_REQUEST['table'])), "</p>\n";
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"drop\">\n";
+ echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+ echo "<input type=\"hidden\" name=\"trigger\" value=\"", htmlspecialchars($_REQUEST['trigger']), "\">\n";
+ echo $misc->form;
+ echo "<input type=\"submit\" name=\"choice\" value=\"{$strYes}\"> <input type=\"submit\" name=\"choice\" value=\"{$strNo}\">\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $localData->dropTrigger($_POST['trigger'], $_POST['table']);
+ if ($status == 0)
+ doDefault($strTriggerDropped);
+ else
+ doDefault($strTriggerDroppedBad);
+ }
+
+ }
+
+ /**
+ * List all the triggers on the table
+ */
+ function doDefault($msg = '') {
+ global $data, $localData, $misc;
+ global $PHP_SELF;
+ global $strTriggers, $strName, $strActions, $strNoTriggers, $strCreateTrigger, $strDrop;
+
+ $misc->printTableNav();
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": ", htmlspecialchars($_REQUEST['table']), ": {$strTriggers}</h2>\n";
+ $misc->printMsg($msg);
+
+ $triggers = &$localData->getTriggers($_REQUEST['table']);
+
+ if ($triggers->recordCount() > 0) {
+ echo "<table>\n";
+ echo "<tr><th class=\"data\">{$strName}</th><th class=\"data\">{$strActions}</th>\n";
+ $i = 0;
+
+ while (!$triggers->EOF) {
+ $id = ( ($i % 2 ) == 0 ? '1' : '2' );
+ echo "<tr><td class=\"data{$id}\">", htmlspecialchars( $triggers->f[$data->tgFields['tgname']]), "</td>";
+ echo "<td class=\"data{$id}\">";
+ echo "<a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&trigger=", htmlspecialchars( $triggers->f[$data->tgFields['tgname']]),
+ "&table=", htmlspecialchars($_REQUEST['table']), "\">{$strDrop}</td></tr>\n";
+
+ $triggers->moveNext();
+ $i++;
+ }
+
+ echo "</table>\n";
+ }
+ else
+ echo "<p>{$strNoTriggers}</p>\n";
+
+ //echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}&table=", htmlspecialchars($_REQUEST['table']), "\">{$strCreateTrigger}</a></p>\n";
+ }
+
+ $misc->printHeader($strTables . ' - ' . $_REQUEST['table'] . ' - ' . $strTriggers);
+
+ switch ($action) {
+ case 'save_create':
+ doSaveCreate();
+ break;
+ case 'create':
+ doCreate();
+ break;
+ case 'drop':
+ if ($_POST['choice'] == $strYes) doDrop(false);
+ else doDefault();
+ break;
+ case 'confirm_drop':
+ doDrop(true);
+ break;
+ default:
+ doDefault();
+ break;
+ }
+
+ $misc->printFooter();
+
+?>