#include "postgres.h"
#include "catalog/objectaccess.h"
+#include "catalog/pg_class.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_proc.h"
(void *) &drop_arg);
}
+/*
+ * RunObjectTruncateHook
+ *
+ * It is the entrypoint of OAT_TRUNCATE event
+ */
+void
+RunObjectTruncateHook(Oid objectId)
+{
+ /* caller should check, but just in case... */
+ Assert(object_access_hook != NULL);
+
+ (*object_access_hook) (OAT_TRUNCATE,
+ RelationRelationId, objectId, 0,
+ NULL);
+}
+
/*
* RunObjectPostAlterHook
*
* creation or altering, because OAT_POST_CREATE or OAT_POST_ALTER are
* sufficient for extensions to track these kind of checks.
*
+ * OAT_TRUNCATE should be invoked just before truncation of objects. This
+ * event is equivalent to truncate permission on a relation under the
+ * default access control mechanism.
+ *
* Other types may be added in the future.
*/
typedef enum ObjectAccessType
OAT_DROP,
OAT_POST_ALTER,
OAT_NAMESPACE_SEARCH,
- OAT_FUNCTION_EXECUTE
+ OAT_FUNCTION_EXECUTE,
+ OAT_TRUNCATE
} ObjectAccessType;
/*
bool is_internal);
extern void RunObjectDropHook(Oid classId, Oid objectId, int subId,
int dropflags);
+extern void RunObjectTruncateHook(Oid objectId);
extern void RunObjectPostAlterHook(Oid classId, Oid objectId, int subId,
Oid auxiliaryId, bool is_internal);
extern bool RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation);
(dropflags)); \
} while(0)
+#define InvokeObjectTruncateHook(objectId) \
+ do { \
+ if (object_access_hook) \
+ RunObjectTruncateHook(objectId); \
+ } while(0)
+
#define InvokeObjectPostAlterHook(classId,objectId,subId) \
InvokeObjectPostAlterHookArg((classId),(objectId),(subId), \
InvalidOid,false)