66#include "commands/trigger.h" /* -"- and triggers */
77#include <ctype.h> /* tolower () */
88
9- HeapTuple noup (void );
9+ extern Datum noup (PG_FUNCTION_ARGS );
1010
1111/*
1212 * noup () -- revoke permission on column
@@ -16,9 +16,10 @@ HeapTuplenoup(void);
1616 * EXECUTE PROCEDURE noup ('col').
1717 */
1818
19- HeapTuple /* have to return HeapTuple to Executor */
20- noup ()
19+ Datum
20+ noup (PG_FUNCTION_ARGS )
2121{
22+ TriggerData * trigdata = (TriggerData * )fcinfo -> context ;
2223Trigger * trigger ;/* to get trigger name */
2324int nargs ;/* # of args specified in CREATE TRIGGER */
2425char * * args ;/* arguments: column names and table name */
@@ -36,42 +37,35 @@ noup()
3637 */
3738
3839/* 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 " );
4142
4243/* 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" );
4546
4647/* 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" );
4950
5051/* 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" );
5354
5455/* check new Tuple */
55- tuple = CurrentTriggerData -> tg_newtuple ;
56+ tuple = trigdata -> tg_newtuple ;
5657
57- trigger = CurrentTriggerData -> tg_trigger ;
58+ trigger = trigdata -> tg_trigger ;
5859nargs = trigger -> tgnargs ;
5960args = trigger -> tgargs ;
6061
6162nkeys = nargs ;
62- rel = CurrentTriggerData -> tg_relation ;
63+ rel = trigdata -> tg_relation ;
6364tupdesc = rel -> rd_att ;
6465
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-
7266/* Connect to SPI manager */
7367if ((ret = SPI_connect ())< 0 )
74- elog (WARN ,"noup: SPI_connect returned %d" ,ret );
68+ elog (ERROR ,"noup: SPI_connect returned %d" ,ret );
7569
7670/*
7771 * We use SPI plan preparation feature, so allocate space to place key
8781
8882/* Bad guys may give us un-existing column in CREATE TRIGGER */
8983if (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" ,
9185args [i ],SPI_getrelname (rel ));
9286
9387/* Well, get binary (in internal format) value of column */
@@ -99,13 +93,13 @@ noup()
9993if (!isnull )
10094{
10195
102- elog (WARN ,"%s: update not allowed" ,args [i ]);
96+ elog (NOTICE ,"%s: update not allowed" ,args [i ]);
10397SPI_finish ();
104- return NULL ;
98+ return PointerGetDatum ( NULL ) ;
10599}
106100
107101}
108102
109103SPI_finish ();
110- return (tuple );
104+ return PointerGetDatum (tuple );
111105}