6
6
#include "commands/trigger.h" /* -"- and triggers */
7
7
#include <ctype.h> /* tolower () */
8
8
9
- HeapTuple noup (void );
9
+ extern Datum noup (PG_FUNCTION_ARGS );
10
10
11
11
/*
12
12
* noup () -- revoke permission on column
@@ -16,9 +16,10 @@ HeapTuple noup(void);
16
16
* EXECUTE PROCEDURE noup ('col').
17
17
*/
18
18
19
- HeapTuple /* have to return HeapTuple to Executor */
20
- noup ()
19
+ Datum
20
+ noup (PG_FUNCTION_ARGS )
21
21
{
22
+ TriggerData * trigdata = (TriggerData * ) fcinfo -> context ;
22
23
Trigger * trigger ; /* to get trigger name */
23
24
int nargs ; /* # of args specified in CREATE TRIGGER */
24
25
char * * args ; /* arguments: column names and table name */
@@ -36,42 +37,35 @@ noup()
36
37
*/
37
38
38
39
/* Called by trigger manager ? */
39
- if (!CurrentTriggerData )
40
- elog (WARN , "noup: triggers are not initialized " );
40
+ if (!CALLED_AS_TRIGGER ( fcinfo ) )
41
+ elog (ERROR , "noup: not fired by trigger manager " );
41
42
42
43
/* Should be called for ROW trigger */
43
- if (TRIGGER_FIRED_FOR_STATEMENT (CurrentTriggerData -> tg_event ))
44
- elog (WARN , "noup: can't process STATEMENT events" );
44
+ if (TRIGGER_FIRED_FOR_STATEMENT (trigdata -> tg_event ))
45
+ elog (ERROR , "noup: can't process STATEMENT events" );
45
46
46
47
/* Not should be called for INSERT */
47
- if (TRIGGER_FIRED_BY_INSERT (CurrentTriggerData -> tg_event ))
48
- elog (WARN , "noup: can't process INSERT events" );
48
+ if (TRIGGER_FIRED_BY_INSERT (trigdata -> tg_event ))
49
+ elog (ERROR , "noup: can't process INSERT events" );
49
50
50
51
/* Not should be called for DELETE */
51
- else if (TRIGGER_FIRED_BY_DELETE (CurrentTriggerData -> tg_event ))
52
- elog (WARN , "noup: can't process DELETE events" );
52
+ else if (TRIGGER_FIRED_BY_DELETE (trigdata -> tg_event ))
53
+ elog (ERROR , "noup: can't process DELETE events" );
53
54
54
55
/* check new Tuple */
55
- tuple = CurrentTriggerData -> tg_newtuple ;
56
+ tuple = trigdata -> tg_newtuple ;
56
57
57
- trigger = CurrentTriggerData -> tg_trigger ;
58
+ trigger = trigdata -> tg_trigger ;
58
59
nargs = trigger -> tgnargs ;
59
60
args = trigger -> tgargs ;
60
61
61
62
nkeys = nargs ;
62
- rel = CurrentTriggerData -> tg_relation ;
63
+ rel = trigdata -> tg_relation ;
63
64
tupdesc = rel -> rd_att ;
64
65
65
- /*
66
- * Setting CurrentTriggerData to NULL prevents direct calls to trigger
67
- * functions in queries. Normally, trigger functions have to be called
68
- * by trigger manager code only.
69
- */
70
- CurrentTriggerData = NULL ;
71
-
72
66
/* Connect to SPI manager */
73
67
if ((ret = SPI_connect ()) < 0 )
74
- elog (WARN , "noup: SPI_connect returned %d" , ret );
68
+ elog (ERROR , "noup: SPI_connect returned %d" , ret );
75
69
76
70
/*
77
71
* We use SPI plan preparation feature, so allocate space to place key
87
81
88
82
/* Bad guys may give us un-existing column in CREATE TRIGGER */
89
83
if (fnumber < 0 )
90
- elog (WARN , "noup: there is no attribute %s in relation %s" ,
84
+ elog (ERROR , "noup: there is no attribute %s in relation %s" ,
91
85
args [i ], SPI_getrelname (rel ));
92
86
93
87
/* Well, get binary (in internal format) value of column */
@@ -99,13 +93,13 @@ noup()
99
93
if (!isnull )
100
94
{
101
95
102
- elog (WARN , "%s: update not allowed" , args [i ]);
96
+ elog (NOTICE , "%s: update not allowed" , args [i ]);
103
97
SPI_finish ();
104
- return NULL ;
98
+ return PointerGetDatum ( NULL ) ;
105
99
}
106
100
107
101
}
108
102
109
103
SPI_finish ();
110
- return (tuple );
104
+ return PointerGetDatum (tuple );
111
105
}
0 commit comments