Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / src / include / commands / trigger.h
blob7dad6b4c816a17f25e5c7fd47cacbbe2ea0b4411
1 /*-------------------------------------------------------------------------
3 * trigger.h
4 * Declarations for trigger handling.
6 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * $PostgreSQL$
11 *-------------------------------------------------------------------------
13 #ifndef TRIGGER_H
14 #define TRIGGER_H
16 #include "nodes/execnodes.h"
17 #include "nodes/parsenodes.h"
20 * TriggerData is the node type that is passed as fmgr "context" info
21 * when a function is called by the trigger manager.
24 #define CALLED_AS_TRIGGER(fcinfo) \
25 ((fcinfo)->context != NULL && IsA((fcinfo)->context, TriggerData))
27 typedef uint32 TriggerEvent;
29 typedef struct TriggerData
31 NodeTag type;
32 TriggerEvent tg_event;
33 Relation tg_relation;
34 HeapTuple tg_trigtuple;
35 HeapTuple tg_newtuple;
36 Trigger *tg_trigger;
37 Buffer tg_trigtuplebuf;
38 Buffer tg_newtuplebuf;
39 } TriggerData;
42 * TriggerEvent bit flags
44 * Note that we assume different event types (INSERT/DELETE/UPDATE/TRUNCATE)
45 * can't be OR'd together in a single TriggerEvent. This is unlike the
46 * situation for pg_trigger rows, so pg_trigger.tgtype uses a different
47 * representation!
49 #define TRIGGER_EVENT_INSERT 0x00000000
50 #define TRIGGER_EVENT_DELETE 0x00000001
51 #define TRIGGER_EVENT_UPDATE 0x00000002
52 #define TRIGGER_EVENT_TRUNCATE 0x00000003
53 #define TRIGGER_EVENT_OPMASK 0x00000003
54 #define TRIGGER_EVENT_ROW 0x00000004
55 #define TRIGGER_EVENT_BEFORE 0x00000008
57 /* More TriggerEvent flags, used only within trigger.c */
59 #define AFTER_TRIGGER_DEFERRABLE 0x00000010
60 #define AFTER_TRIGGER_INITDEFERRED 0x00000020
62 #define TRIGGER_FIRED_BY_INSERT(event) \
63 (((TriggerEvent) (event) & TRIGGER_EVENT_OPMASK) == \
64 TRIGGER_EVENT_INSERT)
66 #define TRIGGER_FIRED_BY_DELETE(event) \
67 (((TriggerEvent) (event) & TRIGGER_EVENT_OPMASK) == \
68 TRIGGER_EVENT_DELETE)
70 #define TRIGGER_FIRED_BY_UPDATE(event) \
71 (((TriggerEvent) (event) & TRIGGER_EVENT_OPMASK) == \
72 TRIGGER_EVENT_UPDATE)
74 #define TRIGGER_FIRED_BY_TRUNCATE(event) \
75 (((TriggerEvent) (event) & TRIGGER_EVENT_OPMASK) == \
76 TRIGGER_EVENT_TRUNCATE)
78 #define TRIGGER_FIRED_FOR_ROW(event) \
79 ((TriggerEvent) (event) & TRIGGER_EVENT_ROW)
81 #define TRIGGER_FIRED_FOR_STATEMENT(event) \
82 (!TRIGGER_FIRED_FOR_ROW (event))
84 #define TRIGGER_FIRED_BEFORE(event) \
85 ((TriggerEvent) (event) & TRIGGER_EVENT_BEFORE)
87 #define TRIGGER_FIRED_AFTER(event) \
88 (!TRIGGER_FIRED_BEFORE (event))
91 * Definitions for the replication role based firing.
93 #define SESSION_REPLICATION_ROLE_ORIGIN 0
94 #define SESSION_REPLICATION_ROLE_REPLICA 1
95 #define SESSION_REPLICATION_ROLE_LOCAL 2
96 extern PGDLLIMPORT int SessionReplicationRole;
99 * States at which a trigger can be fired. These are the
100 * possible values for pg_trigger.tgenabled.
102 #define TRIGGER_FIRES_ON_ORIGIN 'O'
103 #define TRIGGER_FIRES_ALWAYS 'A'
104 #define TRIGGER_FIRES_ON_REPLICA 'R'
105 #define TRIGGER_DISABLED 'D'
107 extern Oid CreateTrigger(CreateTrigStmt *stmt, Oid constraintOid,
108 bool checkPermissions);
110 extern void DropTrigger(Oid relid, const char *trigname,
111 DropBehavior behavior, bool missing_ok);
112 extern void RemoveTriggerById(Oid trigOid);
114 extern void renametrig(Oid relid, const char *oldname, const char *newname);
116 extern void EnableDisableTrigger(Relation rel, const char *tgname,
117 char fires_when, bool skip_system);
119 extern void RelationBuildTriggers(Relation relation);
121 extern TriggerDesc *CopyTriggerDesc(TriggerDesc *trigdesc);
123 extern void FreeTriggerDesc(TriggerDesc *trigdesc);
125 extern void ExecBSInsertTriggers(EState *estate,
126 ResultRelInfo *relinfo);
127 extern void ExecASInsertTriggers(EState *estate,
128 ResultRelInfo *relinfo);
129 extern HeapTuple ExecBRInsertTriggers(EState *estate,
130 ResultRelInfo *relinfo,
131 HeapTuple trigtuple);
132 extern void ExecARInsertTriggers(EState *estate,
133 ResultRelInfo *relinfo,
134 HeapTuple trigtuple);
135 extern void ExecBSDeleteTriggers(EState *estate,
136 ResultRelInfo *relinfo);
137 extern void ExecASDeleteTriggers(EState *estate,
138 ResultRelInfo *relinfo);
139 extern bool ExecBRDeleteTriggers(EState *estate,
140 ResultRelInfo *relinfo,
141 ItemPointer tupleid);
142 extern void ExecARDeleteTriggers(EState *estate,
143 ResultRelInfo *relinfo,
144 ItemPointer tupleid);
145 extern void ExecBSUpdateTriggers(EState *estate,
146 ResultRelInfo *relinfo);
147 extern void ExecASUpdateTriggers(EState *estate,
148 ResultRelInfo *relinfo);
149 extern HeapTuple ExecBRUpdateTriggers(EState *estate,
150 ResultRelInfo *relinfo,
151 ItemPointer tupleid,
152 HeapTuple newtuple);
153 extern void ExecARUpdateTriggers(EState *estate,
154 ResultRelInfo *relinfo,
155 ItemPointer tupleid,
156 HeapTuple newtuple);
157 extern void ExecBSTruncateTriggers(EState *estate,
158 ResultRelInfo *relinfo);
159 extern void ExecASTruncateTriggers(EState *estate,
160 ResultRelInfo *relinfo);
162 extern void AfterTriggerBeginXact(void);
163 extern void AfterTriggerBeginQuery(void);
164 extern void AfterTriggerEndQuery(EState *estate);
165 extern void AfterTriggerFireDeferred(void);
166 extern void AfterTriggerEndXact(bool isCommit);
167 extern void AfterTriggerBeginSubXact(void);
168 extern void AfterTriggerEndSubXact(bool isCommit);
169 extern void AfterTriggerSetState(ConstraintsSetStmt *stmt);
170 extern bool AfterTriggerPendingOnRel(Oid relid);
174 * in utils/adt/ri_triggers.c
176 extern bool RI_FKey_keyequal_upd_pk(Trigger *trigger, Relation pk_rel,
177 HeapTuple old_row, HeapTuple new_row);
178 extern bool RI_FKey_keyequal_upd_fk(Trigger *trigger, Relation fk_rel,
179 HeapTuple old_row, HeapTuple new_row);
180 extern bool RI_Initial_Check(Trigger *trigger,
181 Relation fk_rel, Relation pk_rel);
183 /* result values for RI_FKey_trigger_type: */
184 #define RI_TRIGGER_PK 1 /* is a trigger on the PK relation */
185 #define RI_TRIGGER_FK 2 /* is a trigger on the FK relation */
186 #define RI_TRIGGER_NONE 0 /* is not an RI trigger function */
188 extern int RI_FKey_trigger_type(Oid tgfoid);
190 #endif /* TRIGGER_H */