]> granicus.if.org Git - postgresql/commitdiff
Fix confusion between ObjectType and ObjectClass
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 11 Apr 2013 14:59:47 +0000 (11:59 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 11 Apr 2013 14:59:47 +0000 (11:59 -0300)
Per report by Will Leinweber and Peter Eisentraut

src/backend/catalog/dependency.c
src/backend/commands/event_trigger.c
src/include/commands/event_trigger.h

index 286137c2513a47124846fc05ffc791857b0ac6de..6b7a51947c9ef381d5544c4d90184c90227279e1 100644 (file)
@@ -210,7 +210,7 @@ deleteObjectsInList(ObjectAddresses *targetObjects, Relation *depRel,
                        ObjectAddress *thisobj = targetObjects->refs + i;
 
                        if ((!(flags & PERFORM_DELETION_INTERNAL)) &&
-                               EventTriggerSupportsObjectType(getObjectClass(thisobj)))
+                               EventTriggerSupportsObjectClass(getObjectClass(thisobj)))
                        {
                                EventTriggerSQLDropAddObject(thisobj);
                        }
index ed5240d63b0192ddb27dca7343dd8e98ba324245..0a392d5dc0491a5b20bde882cb426fe7af59cc4e 100644 (file)
@@ -905,9 +905,96 @@ EventTriggerSupportsObjectType(ObjectType obtype)
                case OBJECT_EVENT_TRIGGER:
                        /* no support for event triggers on event triggers */
                        return false;
-               default:
+               case OBJECT_AGGREGATE:
+               case OBJECT_ATTRIBUTE:
+               case OBJECT_CAST:
+               case OBJECT_COLUMN:
+               case OBJECT_CONSTRAINT:
+               case OBJECT_COLLATION:
+               case OBJECT_CONVERSION:
+               case OBJECT_DOMAIN:
+               case OBJECT_EXTENSION:
+               case OBJECT_FDW:
+               case OBJECT_FOREIGN_SERVER:
+               case OBJECT_FOREIGN_TABLE:
+               case OBJECT_FUNCTION:
+               case OBJECT_INDEX:
+               case OBJECT_LANGUAGE:
+               case OBJECT_LARGEOBJECT:
+               case OBJECT_MATVIEW:
+               case OBJECT_OPCLASS:
+               case OBJECT_OPERATOR:
+               case OBJECT_OPFAMILY:
+               case OBJECT_RULE:
+               case OBJECT_SCHEMA:
+               case OBJECT_SEQUENCE:
+               case OBJECT_TABLE:
+               case OBJECT_TRIGGER:
+               case OBJECT_TSCONFIGURATION:
+               case OBJECT_TSDICTIONARY:
+               case OBJECT_TSPARSER:
+               case OBJECT_TSTEMPLATE:
+               case OBJECT_TYPE:
+               case OBJECT_VIEW:
+                       return true;
+       }
+       return true;
+}
+
+/*
+ * Do event triggers support this object class?
+ */
+bool
+EventTriggerSupportsObjectClass(ObjectClass objclass)
+{
+       switch (objclass)
+       {
+               case OCLASS_DATABASE:
+               case OCLASS_TBLSPACE:
+               case OCLASS_ROLE:
+                       /* no support for global objects */
+                       return false;
+               case OCLASS_EVENT_TRIGGER:
+                       /* no support for event triggers on event triggers */
+                       return false;
+               case OCLASS_CLASS:
+               case OCLASS_PROC:
+               case OCLASS_TYPE:
+               case OCLASS_CAST:
+               case OCLASS_COLLATION:
+               case OCLASS_CONSTRAINT:
+               case OCLASS_CONVERSION:
+               case OCLASS_DEFAULT:
+               case OCLASS_LANGUAGE:
+               case OCLASS_LARGEOBJECT:
+               case OCLASS_OPERATOR:
+               case OCLASS_OPCLASS:
+               case OCLASS_OPFAMILY:
+               case OCLASS_AMOP:
+               case OCLASS_AMPROC:
+               case OCLASS_REWRITE:
+               case OCLASS_TRIGGER:
+               case OCLASS_SCHEMA:
+               case OCLASS_TSPARSER:
+               case OCLASS_TSDICT:
+               case OCLASS_TSTEMPLATE:
+               case OCLASS_TSCONFIG:
+               case OCLASS_FDW:
+               case OCLASS_FOREIGN_SERVER:
+               case OCLASS_USER_MAPPING:
+               case OCLASS_DEFACL:
+               case OCLASS_EXTENSION:
+                       return true;
+
+               case MAX_OCLASS:
+                       /*
+                        * This shouldn't ever happen, but we keep the case to avoid a
+                        * compiler warning without a "default" clause in the switch.
+                        */
+                       Assert(false);
                        break;
        }
+
        return true;
 }
 
@@ -1011,7 +1098,7 @@ EventTriggerSQLDropAddObject(ObjectAddress *object)
        if (!currentEventTriggerState)
                return;
 
-       Assert(EventTriggerSupportsObjectType(getObjectClass(object)));
+       Assert(EventTriggerSupportsObjectClass(getObjectClass(object)));
 
        /* don't report temp schemas */
        if (object->classId == NamespaceRelationId &&
index 8ea99c19c998f28d554a0d241329ec3b8949ba97..848d4a3e45ba5796f58ce346e9b0fdda96b62375 100644 (file)
@@ -13,6 +13,7 @@
 #ifndef EVENT_TRIGGER_H
 #define EVENT_TRIGGER_H
 
+#include "catalog/dependency.h"
 #include "catalog/objectaddress.h"
 #include "catalog/pg_event_trigger.h"
 #include "nodes/parsenodes.h"
@@ -41,6 +42,7 @@ extern Oid AlterEventTriggerOwner(const char *name, Oid newOwnerId);
 extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId);
 
 extern bool EventTriggerSupportsObjectType(ObjectType obtype);
+extern bool EventTriggerSupportsObjectClass(ObjectClass objclass);
 extern void EventTriggerDDLCommandStart(Node *parsetree);
 extern void EventTriggerDDLCommandEnd(Node *parsetree);
 extern void EventTriggerSQLDrop(Node *parsetree);