Skip to content

Commit ccecf1f

Browse files
Jan WieckJan Wieck
authored andcommitted
Added utils/adt/ri_triggers with empty shells for the
FOREIGN KEY triggers. Added pg_proc entries for all the new functions. Jan
1 parent daaeafd commit ccecf1f

File tree

5 files changed

+226
-6
lines changed

5 files changed

+226
-6
lines changed

src/backend/commands/trigger.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ CreateTrigger(CreateTrigStmt *stmt)
155155
if (((Form_pg_proc) GETSTRUCT(tuple))->prorettype != 0)
156156
elog(ERROR, "CreateTrigger: function %s() must return OPAQUE",
157157
stmt->funcname);
158-
if (((Form_pg_proc) GETSTRUCT(tuple))->prolang != ClanguageId)
158+
if (((Form_pg_proc) GETSTRUCT(tuple))->prolang != ClanguageId &&
159+
((Form_pg_proc) GETSTRUCT(tuple))->prolang != INTERNALlanguageId)
159160
{
160161
HeapTuple langTup;
161162

@@ -166,7 +167,7 @@ CreateTrigger(CreateTrigStmt *stmt)
166167
elog(ERROR, "CreateTrigger: cache lookup for PL failed");
167168

168169
if (((Form_pg_language) GETSTRUCT(langTup))->lanispl == false)
169-
elog(ERROR, "CreateTrigger: only C and PL functions are supported");
170+
elog(ERROR, "CreateTrigger: only builtin, C and PL functions are supported");
170171
}
171172

172173
MemSet(nulls, ' ', Natts_pg_trigger * sizeof(char));

src/backend/utils/adt/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for utils/adt
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.25 1999/07/22 18:30:08 momjian Exp $
7+
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.26 1999/09/30 14:54:22 wieck Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -34,7 +34,8 @@ OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o chunk.o \
3434
oid.o oracle_compat.o \
3535
regexp.o regproc.o ruleutils.o selfuncs.o sets.o \
3636
tid.o timestamp.o varchar.o varlena.o version.o \
37-
network.o mac.o inet_net_ntop.o inet_net_pton.o
37+
network.o mac.o inet_net_ntop.o inet_net_pton.o \
38+
ri_triggers.o
3839

3940
all: SUBSYS.o
4041

src/backend/utils/adt/ri_triggers.c

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/* ----------
2+
* ri_triggers.c
3+
*
4+
* Generic trigger procedures for referential integrity constraint
5+
* checks.
6+
*
7+
* 1999 Jan Wieck
8+
*
9+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.1 1999/09/30 14:54:22 wieck Exp $
10+
*
11+
* ----------
12+
*/
13+
14+
#include "postgres.h"
15+
#include "fmgr.h"
16+
17+
#include "access/heapam.h"
18+
#include "catalog/pg_proc.h"
19+
#include "catalog/pg_type.h"
20+
#include "commands/trigger.h"
21+
#include "executor/spi.h"
22+
#include "utils/builtins.h"
23+
#include "utils/syscache.h"
24+
25+
/* ----------
26+
* RI_FKey_check_ins -
27+
*
28+
* Check foreign key existance at insert event on FK table.
29+
* ----------
30+
*/
31+
HeapTuple
32+
RI_FKey_check_ins (FmgrInfo *proinfo)
33+
{
34+
CurrentTriggerData = NULL;
35+
36+
elog(NOTICE, "RI_FKey_check_ins() called\n");
37+
return NULL;
38+
}
39+
40+
41+
/* ----------
42+
* RI_FKey_check_upd -
43+
*
44+
* Check foreign key existance at update event on FK table.
45+
* ----------
46+
*/
47+
HeapTuple
48+
RI_FKey_check_upd (FmgrInfo *proinfo)
49+
{
50+
CurrentTriggerData = NULL;
51+
52+
elog(NOTICE, "RI_FKey_check_upd() called\n");
53+
return NULL;
54+
}
55+
56+
57+
/* ----------
58+
* RI_FKey_cascade_del -
59+
*
60+
* Cascaded delete foreign key references at delete event on PK table.
61+
* ----------
62+
*/
63+
HeapTuple
64+
RI_FKey_cascade_del (FmgrInfo *proinfo)
65+
{
66+
CurrentTriggerData = NULL;
67+
68+
elog(NOTICE, "RI_FKey_cascade_del() called\n");
69+
return NULL;
70+
}
71+
72+
73+
/* ----------
74+
* RI_FKey_cascade_upd -
75+
*
76+
* Cascaded update/delete foreign key references at update event on PK table.
77+
* ----------
78+
*/
79+
HeapTuple
80+
RI_FKey_cascade_upd (FmgrInfo *proinfo)
81+
{
82+
CurrentTriggerData = NULL;
83+
84+
elog(NOTICE, "RI_FKey_cascade_upd() called\n");
85+
return NULL;
86+
}
87+
88+
89+
/* ----------
90+
* RI_FKey_restrict_del -
91+
*
92+
* Restrict delete from PK table to rows unreferenced by foreign key.
93+
* ----------
94+
*/
95+
HeapTuple
96+
RI_FKey_restrict_del (FmgrInfo *proinfo)
97+
{
98+
CurrentTriggerData = NULL;
99+
100+
elog(NOTICE, "RI_FKey_restrict_del() called\n");
101+
return NULL;
102+
}
103+
104+
105+
/* ----------
106+
* RI_FKey_restrict_upd -
107+
*
108+
* Restrict update of PK to rows unreferenced by foreign key.
109+
* ----------
110+
*/
111+
HeapTuple
112+
RI_FKey_restrict_upd (FmgrInfo *proinfo)
113+
{
114+
CurrentTriggerData = NULL;
115+
116+
elog(NOTICE, "RI_FKey_restrict_upd() called\n");
117+
return NULL;
118+
}
119+
120+
121+
/* ----------
122+
* RI_FKey_setnull_del -
123+
*
124+
* Set foreign key references to NULL values at delete event on PK table.
125+
* ----------
126+
*/
127+
HeapTuple
128+
RI_FKey_setnull_del (FmgrInfo *proinfo)
129+
{
130+
CurrentTriggerData = NULL;
131+
132+
elog(NOTICE, "RI_FKey_setnull_del() called\n");
133+
return NULL;
134+
}
135+
136+
137+
/* ----------
138+
* RI_FKey_setnull_upd -
139+
*
140+
* Set foreign key references to NULL at update event on PK table.
141+
* ----------
142+
*/
143+
HeapTuple
144+
RI_FKey_setnull_upd (FmgrInfo *proinfo)
145+
{
146+
CurrentTriggerData = NULL;
147+
148+
elog(NOTICE, "RI_FKey_setnull_upd() called\n");
149+
return NULL;
150+
}
151+
152+
153+
/* ----------
154+
* RI_FKey_setdefault_del -
155+
*
156+
* Set foreign key references to defaults at delete event on PK table.
157+
* ----------
158+
*/
159+
HeapTuple
160+
RI_FKey_setdefault_del (FmgrInfo *proinfo)
161+
{
162+
CurrentTriggerData = NULL;
163+
164+
elog(NOTICE, "RI_FKey_setdefault_del() called\n");
165+
return NULL;
166+
}
167+
168+
169+
/* ----------
170+
* RI_FKey_setdefault_upd -
171+
*
172+
* Set foreign key references to defaults at update event on PK table.
173+
* ----------
174+
*/
175+
HeapTuple
176+
RI_FKey_setdefault_upd (FmgrInfo *proinfo)
177+
{
178+
CurrentTriggerData = NULL;
179+
180+
elog(NOTICE, "RI_FKey_setdefault_upd() called\n");
181+
return NULL;
182+
}
183+
184+

src/include/catalog/pg_proc.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_proc.h,v 1.103 1999/09/29 21:13:30 wieck Exp $
9+
* $Id: pg_proc.h,v 1.104 1999/09/30 14:54:23 wieck Exp $
1010
*
1111
* NOTES
1212
* The script catalog/genbki.sh reads this file and generates .bki
@@ -2112,6 +2112,28 @@ DESCR("user name by UID (with fallback)");
21122112
DATA(insert OID = 1643 ( pg_get_indexdef PGUID 11 f t f 1 f 25 "26" 100 0 0 100 pg_get_indexdef - ));
21132113
DESCR("index description");
21142114

2115+
/* Generic referential integrity constraint triggers */
2116+
DATA(insert OID = 1644 ( RI_FKey_check_ins PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_check_ins - ));
2117+
DESCR("referential integrity FOREIGN KEY ... REFERENCES");
2118+
DATA(insert OID = 1645 ( RI_FKey_check_upd PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_check_upd - ));
2119+
DESCR("referential integrity FOREIGN KEY ... REFERENCES");
2120+
DATA(insert OID = 1646 ( RI_FKey_cascade_del PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_cascade_del - ));
2121+
DESCR("referential integrity ON DELETE CASCADE");
2122+
DATA(insert OID = 1647 ( RI_FKey_cascade_upd PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_cascade_upd - ));
2123+
DESCR("referential integrity ON UPDATE CASCADE");
2124+
DATA(insert OID = 1648 ( RI_FKey_restrict_del PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_restrict_del - ));
2125+
DESCR("referential integrity ON DELETE RESTRICT");
2126+
DATA(insert OID = 1649 ( RI_FKey_restrict_upd PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_restrict_upd - ));
2127+
DESCR("referential integrity ON UPDATE RESTRICT");
2128+
DATA(insert OID = 1650 ( RI_FKey_setnull_del PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_setnull_del - ));
2129+
DESCR("referential integrity ON DELETE SET NULL");
2130+
DATA(insert OID = 1651 ( RI_FKey_setnull_upd PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_setnull_upd - ));
2131+
DESCR("referential integrity ON UPDATE SET NULL");
2132+
DATA(insert OID = 1652 ( RI_FKey_setdefault_del PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_setdefault_del - ));
2133+
DESCR("referential integrity ON DELETE SET DEFAULT");
2134+
DATA(insert OID = 1653 ( RI_FKey_setdefault_upd PGUID 11 f t f 0 f 0 "" 100 0 0 100 RI_FKey_setdefault_upd - ));
2135+
DESCR("referential integrity ON UPDATE SET DEFAULT");
2136+
21152137
/* for mac type support */
21162138
DATA(insert OID = 436 ( macaddr_in PGUID 11 f t t 1 f 829 "0" 100 0 0 100 macaddr_in - ));
21172139
DESCR("(internal)");

src/include/utils/builtins.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: builtins.h,v 1.86 1999/09/29 21:13:31 wieck Exp $
9+
* $Id: builtins.h,v 1.87 1999/09/30 14:54:24 wieck Exp $
1010
*
1111
* NOTES
1212
* This should normally only be included by fmgr.h.
@@ -30,6 +30,7 @@
3030
#include "utils/int8.h"
3131
#include "utils/nabstime.h"
3232
#include "utils/numeric.h"
33+
#include "access/heapam.h" /* for HeapTuple */
3334

3435
/*
3536
* Defined in adt/
@@ -600,5 +601,16 @@ float32 numeric_float4(Numeric num);
600601
Numeric float8_numeric(float64 val);
601602
float64 numeric_float8(Numeric num);
602603

604+
/* ri_triggers.c */
605+
HeapTuple RI_FKey_check_ins(FmgrInfo *proinfo);
606+
HeapTuple RI_FKey_check_upd(FmgrInfo *proinfo);
607+
HeapTuple RI_FKey_cascade_del(FmgrInfo *proinfo);
608+
HeapTuple RI_FKey_cascade_upd(FmgrInfo *proinfo);
609+
HeapTuple RI_FKey_restrict_del(FmgrInfo *proinfo);
610+
HeapTuple RI_FKey_restrict_upd(FmgrInfo *proinfo);
611+
HeapTuple RI_FKey_setnull_del(FmgrInfo *proinfo);
612+
HeapTuple RI_FKey_setnull_upd(FmgrInfo *proinfo);
613+
HeapTuple RI_FKey_setdefault_del(FmgrInfo *proinfo);
614+
HeapTuple RI_FKey_setdefault_upd(FmgrInfo *proinfo);
603615

604616
#endif /* BUILTINS_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy