Done trigger defs for 7.3+. Can't get parameters of trigger funcs for some bizarre...
authorchriskl <chriskl>
Wed, 26 Mar 2003 02:14:03 +0000 (02:14 +0000)
committerchriskl <chriskl>
Wed, 26 Mar 2003 02:14:03 +0000 (02:14 +0000)
classes/database/Postgres.php
classes/database/Postgres73.php
triggers.php

index ddc1abb2110ffa6cf48a524457df6e82b95cd36f..8c4a336fa9db3a8f529a1ef1056f41f169e12f78 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.65 2003/03/25 15:28:23 chriskl Exp $
+ * $Id: Postgres.php,v 1.66 2003/03/26 02:14:03 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1697,7 +1697,7 @@ class Postgres extends BaseDB {
                }
        
                // Table name
-               $tgdef .= " ON \"{$trigger['tgname']}\" ";
+               $tgdef .= " ON \"{$trigger['relname']}\" ";
                
                // Deferrability
                if ($trigger['tgisconstraint']) {
@@ -1724,14 +1724,20 @@ class Postgres extends BaseDB {
                $tgdef .= "EXECUTE PROCEDURE \"{$trigger['tgfname']}\"(";
                
                // Parameters
-               $params = explode('\\000', $trigger['tgargs']);
-               for ($findx = 0; $findx < $trigger['tgnargs']; $findx++) {
-                       $param = str_replace('\'', '\\\'', $params[$findx]);
-                       $tgdef .= $param;
-                       if ($findx < ($trigger['tgnargs'] - 1))
-                               $tgdef .= ', ';
-               }
-
+               // @@ WHY DOESN'T ALL THIS WORK?
+               // @@ ACTUALLY, pg_unescape_bytea is unnecessary
+               /*
+               if (function_exists('pg_unescape_bytea')) {
+                       $params = explode('\000', pg_unescape_bytea($trigger['tgargs']));
+                       for ($findx = 0; $findx < $trigger['tgnargs']; $findx++) {
+                               $param = str_replace('\'', '\\\'', $params[$findx]);
+                               $tgdef .= $param;
+                               if ($findx < ($trigger['tgnargs'] - 1))
+                                       $tgdef .= ', ';
+                       }
+               }               
+               else */ $tgdef .= "args here";
+               
                // Finish it off
                $tgdef .= ')';
 
index f8e84d167829f1d3f0f4edf723b200fd8ed29859..8892f51b41d44f9ac5def2fe884a689e2812d135 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres73.php,v 1.31 2003/03/25 15:28:24 chriskl Exp $
+ * $Id: Postgres73.php,v 1.32 2003/03/26 02:14:04 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -508,10 +508,13 @@ class Postgres73 extends Postgres72 {
        function &getTriggers($table = '') {
                $this->clean($table);
 
-               $sql = "SELECT t.tgname, NULL AS tgdef
-                       FROM pg_catalog.pg_trigger t
-                       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}'))
+               $sql = "SELECT t.tgname, t.tgisconstraint, t.tgdeferrable, t.tginitdeferred, t.tgtype, 
+                       t.tgargs, t.tgnargs, p.proname AS tgfname, c.relname, NULL AS tgdef
+                       FROM pg_catalog.pg_trigger t LEFT JOIN pg_catalog.pg_proc p
+                       ON t.tgfoid=p.oid, pg_catalog.pg_class c
+                       WHERE t.tgrelid=c.oid
+                       AND c.relname='{$table}'
+                       AND c.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)
index 655d32b3c310ce322d5c20e30ff210236b72bdb0..ffd149f4a12548d27100f61d6192884c5e93f24d 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List triggers on a table
         *
-        * $Id: triggers.php,v 1.9 2003/03/25 15:28:22 chriskl Exp $
+        * $Id: triggers.php,v 1.10 2003/03/26 02:14:03 chriskl Exp $
         */
 
        // Include application functions
        $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
        $PHP_SELF = $_SERVER['PHP_SELF'];
 
-
-       
-       function getTriggerExecTime($type) {
-           $execTime = "AFTER";
-               if ($type & TRIGGER_TYPE_BEFORE) $execTime = "BEFORE";
-
-               return $execTime;
-       }
-
-       function getTriggerEvent($type) {
-               if ($type & TRIGGER_TYPE_INSERT) $event = "INSERT";
-               elseif ($type & TRIGGER_TYPE_DELETE) $event = "DELETE";
-
-               if ($type & TRIGGER_TYPE_UPDATE) $event .= (empty($event)) ? "UPDATE" : " OR UPDATE";
-
-               return $event;
-
-       }
-
        /**
         * Show confirmation of drop and perform actual drop
         */
                        $i = 0;
 
                        while (!$triggers->EOF) {
-                               //$execTime = htmlspecialchars( getTriggerExecTime($triggers->f[$data->tgFields['tgtype']]));
-                               //$event    = htmlspecialchars( getTriggerEvent($triggers->f[$data->tgFields['tgtype']]));
                                $id = ( ($i % 2 ) == 0 ? '1' : '2' );
                                echo "<tr><td class=\"data{$id}\">", htmlspecialchars( $triggers->f[$data->tgFields['tgname']]), "</td>";
-                               echo "<td class=\"data{$id}\">", htmlspecialchars( $triggers->f[$data->tgFields['tgdef']]), "</td>";
                                echo "<td class=\"data{$id}\">";
+                               // Nasty hack to support pre-7.4 PostgreSQL
+                               if ($triggers->f[$data->tgFields['tgdef']] !== null)
+                                       echo htmlspecialchars($triggers->f[$data->tgFields['tgdef']]);
+                               else 
+                                       echo $localData->getTriggerDef($triggers->f);
+                               echo "</td>\n<td class=\"data{$id}\">";
                                echo "<a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&trigger=", urlencode( $triggers->f[$data->tgFields['tgname']]),
                                        "&table=", urlencode($_REQUEST['table']), "\">{$lang['strdrop']}</td></tr>\n";