Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit18952f6

Browse files
committed
Second round of fmgr changes: triggers are now invoked in new style,
CurrentTriggerData is history.
1 parent147ccf5 commit18952f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+658
-666
lines changed

‎contrib/fulltextindex/README

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ sub-string will fit.
5656

5757
The create the function that contains the trigger::
5858

59-
create function fti() returns opaque as '/path/to/fti.so' language 'C';
59+
create function fti() returns opaque as
60+
'/path/to/fti.so' language 'newC';
6061

6162
And finally define the trigger on the 'cds' table:
6263

‎contrib/fulltextindex/fti.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Example:
1818
1919
create function fti() returns opaque as
20-
'/home/boekhold/src/postgresql-6.2/contrib/fti/fti.so' language 'c';
20+
'/home/boekhold/src/postgresql-6.2/contrib/fti/fti.so' language 'newC';
2121
2222
create table title_fti (string varchar(25), id oid);
2323
create index title_fti_idx on title_fti (string);
@@ -61,11 +61,11 @@ select p.* from product p, title_fti f1, title_fti f2 where
6161
that can build the final query automatigally?
6262
*/
6363

64-
HeapTuplefti(void);
65-
char*breakup(char*,char*);
66-
boolis_stopword(char*);
64+
externDatumfti(PG_FUNCTION_ARGS);
65+
staticchar*breakup(char*,char*);
66+
staticboolis_stopword(char*);
6767

68-
boolnew_tuple= false;
68+
staticboolnew_tuple= false;
6969

7070

7171
/* THIS LIST MUST BE IN SORTED ORDER, A BINARY SEARCH IS USED!!!! */
@@ -93,9 +93,10 @@ static intnDeletePlans = 0;
9393
staticEPlan*find_plan(char*ident,EPlan**eplan,int*nplans);
9494

9595
/***********************************************************************/
96-
HeapTuple
97-
fti()
96+
Datum
97+
fti(PG_FUNCTION_ARGS)
9898
{
99+
TriggerData*trigdata= (TriggerData*)fcinfo->context;
99100
Trigger*trigger;/* to get trigger name */
100101
intnargs;/* # of arguments */
101102
char**args;/* arguments */
@@ -119,32 +120,29 @@ fti()
119120
* function\n"); fflush(debug);
120121
*/
121122

122-
if (!CurrentTriggerData)
123-
elog(ERROR,"Full Text Indexing:triggers are not initialized");
124-
if (TRIGGER_FIRED_FOR_STATEMENT(CurrentTriggerData->tg_event))
123+
if (!CALLED_AS_TRIGGER(fcinfo))
124+
elog(ERROR,"Full Text Indexing:not fired by trigger manager");
125+
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
125126
elog(ERROR,"Full Text Indexing: can't process STATEMENT events");
126-
if (TRIGGER_FIRED_BEFORE(CurrentTriggerData->tg_event))
127+
if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
127128
elog(ERROR,"Full Text Indexing: must be fired AFTER event");
128129

129-
if (TRIGGER_FIRED_BY_INSERT(CurrentTriggerData->tg_event))
130+
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
130131
isinsert= true;
131-
if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
132+
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
132133
{
133134
isdelete= true;
134135
isinsert= true;
135136
}
136-
if (TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event))
137+
if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
137138
isdelete= true;
138139

139-
trigger=CurrentTriggerData->tg_trigger;
140-
rel=CurrentTriggerData->tg_relation;
140+
trigger=trigdata->tg_trigger;
141+
rel=trigdata->tg_relation;
141142
relname=SPI_getrelname(rel);
142-
rettuple=CurrentTriggerData->tg_trigtuple;
143+
rettuple=trigdata->tg_trigtuple;
143144
if (isdelete&&isinsert)/* is an UPDATE */
144-
rettuple=CurrentTriggerData->tg_newtuple;
145-
146-
CurrentTriggerData=NULL;/* invalidate 'normal' calls to this
147-
* function */
145+
rettuple=trigdata->tg_newtuple;
148146

149147
if ((ret=SPI_connect())<0)
150148
elog(ERROR,"Full Text Indexing: SPI_connect failed, returned %d\n",ret);
@@ -289,10 +287,10 @@ fti()
289287
}
290288

291289
SPI_finish();
292-
return (rettuple);
290+
returnPointerGetDatum(rettuple);
293291
}
294292

295-
char*
293+
staticchar*
296294
breakup(char*string,char*substring)
297295
{
298296
staticchar*last_start;
@@ -342,7 +340,7 @@ breakup(char *string, char *substring)
342340
}
343341

344342
/* copied from src/backend/parser/keywords.c and adjusted for our situation*/
345-
bool
343+
staticbool
346344
is_stopword(char*text)
347345
{
348346
char**StopLow;/* for list of stop-words */

‎contrib/fulltextindex/fticopy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#
3030
#create function fti() returns opaque as
3131
#'/path/to/fti/file/fti.so'
32-
#language 'C';
32+
#language 'newC';
3333
#
3434
#create trigger my_fti_trigger after update or insert or delete
3535
#on mytable

‎contrib/lo/lo.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
*PostgreSQL type definitions for managed LargeObjects.
33
*
4-
*$Id: lo.c,v 1.2 1999/05/25 16:05:45 momjian Exp $
4+
*$Id: lo.c,v 1.3 2000/05/29 01:59:02 tgl Exp $
55
*
66
*/
77

@@ -37,7 +37,7 @@ Blob *lo_in(char *str);/* Create from String*/
3737
char*lo_out(Blob*addr);/* Output oid as String*/
3838
Oidlo_oid(Blob*addr);/* Return oid as an oid*/
3939
Blob*lo(Oidoid);/* Return Blob based on oid */
40-
HeapTuplelo_manage(void);/* Trigger handler*/
40+
Datumlo_manage(PG_FUNCTION_ARGS);/* Trigger handler*/
4141

4242
/*
4343
* This creates a large object, and set's its OID to the value in the
@@ -139,9 +139,10 @@ lo(Oid oid)
139139
/*
140140
* This handles the trigger that protects us from orphaned large objects
141141
*/
142-
HeapTuple
143-
lo_manage(void)
142+
Datum
143+
lo_manage(PG_FUNCTION_ARGS)
144144
{
145+
TriggerData*trigdata= (TriggerData*)fcinfo->context;
145146
intattnum;/* attribute number to monitor*/
146147
char**args;/* Args containing attr name*/
147148
TupleDesctupdesc;/* Tuple Descriptor*/
@@ -150,28 +151,25 @@ lo_manage(void)
150151
HeapTuplenewtuple=NULL;/* The new value for tuple*/
151152
HeapTupletrigtuple;/* The original value of tuple*/
152153

153-
if (!CurrentTriggerData)
154-
elog(ERROR,"lo:triggers are not initialized");
154+
if (!CALLED_AS_TRIGGER(fcinfo))
155+
elog(ERROR,"lo:not fired by trigger manager");
155156

156157
/*
157-
* Fetch some values fromCurrentTriggerData
158+
* Fetch some values fromtrigdata
158159
*/
159-
newtuple=CurrentTriggerData->tg_newtuple;
160-
trigtuple=CurrentTriggerData->tg_trigtuple;
161-
tupdesc=CurrentTriggerData->tg_relation->rd_att;
162-
args=CurrentTriggerData->tg_trigger->tgargs;
160+
newtuple=trigdata->tg_newtuple;
161+
trigtuple=trigdata->tg_trigtuple;
162+
tupdesc=trigdata->tg_relation->rd_att;
163+
args=trigdata->tg_trigger->tgargs;
163164

164165
/* tuple to return to Executor */
165-
if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
166+
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
166167
rettuple=newtuple;
167168
else
168169
rettuple=trigtuple;
169170

170171
/* Are we deleting the row? */
171-
isdelete=TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event);
172-
173-
/* Were done with it */
174-
CurrentTriggerData=NULL;
172+
isdelete=TRIGGER_FIRED_BY_DELETE(trigdata->tg_event);
175173

176174
/* Get the column were interested in */
177175
attnum=SPI_fnumber(tupdesc,args[0]);
@@ -214,5 +212,5 @@ lo_manage(void)
214212
}
215213
}
216214

217-
return (rettuple);
215+
returnPointerGetDatum(rettuple);
218216
}

‎contrib/lo/lo.sql.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--
22
--PostgreSQL code for LargeObjects
33
--
4-
--$Id: lo.sql.in,v 1.1 1998/06/16 07:07:11 momjian Exp $
4+
--$Id: lo.sql.in,v 1.2 2000/05/29 01:59:02 tgl Exp $
55
--
66

77
load '_OBJWD_/lo_DLSUFFIX_';
@@ -47,7 +47,7 @@ create function lo(oid)
4747
create function lo_manage()
4848
returns opaque
4949
as '_OBJWD_/lo_DLSUFFIX_'
50-
language 'c';
50+
language 'newC';
5151

5252
-- This allows us to map lo to oid
5353
--

‎contrib/noupdate/noup.c

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include"commands/trigger.h"/* -"- and triggers */
77
#include<ctype.h>/* tolower () */
88

9-
HeapTuplenoup(void);
9+
externDatumnoup(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;
2223
Trigger*trigger;/* to get trigger name */
2324
intnargs;/* # of args specified in CREATE TRIGGER */
2425
char**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-
elseif (TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event))
52-
elog(WARN,"noup: can't process DELETE events");
52+
elseif (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;
5859
nargs=trigger->tgnargs;
5960
args=trigger->tgargs;
6061

6162
nkeys=nargs;
62-
rel=CurrentTriggerData->tg_relation;
63+
rel=trigdata->tg_relation;
6364
tupdesc=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 */
7367
if ((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
@@ -87,7 +81,7 @@ noup()
8781

8882
/* Bad guys may give us un-existing column in CREATE TRIGGER */
8983
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",
9185
args[i],SPI_getrelname(rel));
9286

9387
/* Well, get binary (in internal format) value of column */
@@ -99,13 +93,13 @@ noup()
9993
if (!isnull)
10094
{
10195

102-
elog(WARN,"%s: update not allowed",args[i]);
96+
elog(NOTICE,"%s: update not allowed",args[i]);
10397
SPI_finish();
104-
returnNULL;
98+
returnPointerGetDatum(NULL);
10599
}
106100

107101
}
108102

109103
SPI_finish();
110-
return (tuple);
104+
returnPointerGetDatum(tuple);
111105
}

‎contrib/noupdate/noup.source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ DROP FUNCTION noup ();
33
CREATE FUNCTION noup ()
44
RETURNS opaque
55
AS '_OBJWD_/noup_DLSUFFIX_'
6-
LANGUAGE 'c'
6+
LANGUAGE 'newC'
77
;

‎contrib/spi/autoinc.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
#include"executor/spi.h"/* this is what you need to work with SPI */
33
#include"commands/trigger.h"/* -"- and triggers */
44

5-
HeapTupleautoinc(void);
6-
5+
externDatumautoinc(PG_FUNCTION_ARGS);
76
externint4nextval(structvarlena*seqin);
87

9-
HeapTuple
10-
autoinc()
8+
Datum
9+
autoinc(PG_FUNCTION_ARGS)
1110
{
11+
TriggerData*trigdata= (TriggerData*)fcinfo->context;
1212
Trigger*trigger;/* to get trigger name */
1313
intnargs;/* # of arguments */
1414
int*chattrs;/* attnums of attributes to change */
@@ -22,24 +22,24 @@ autoinc()
2222
boolisnull;
2323
inti;
2424

25-
if (!CurrentTriggerData)
26-
elog(ERROR,"autoinc:triggers are not initialized");
27-
if (TRIGGER_FIRED_FOR_STATEMENT(CurrentTriggerData->tg_event))
25+
if (!CALLED_AS_TRIGGER(fcinfo))
26+
elog(ERROR,"autoinc:not fired by trigger manager");
27+
if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
2828
elog(ERROR,"autoinc: can't process STATEMENT events");
29-
if (TRIGGER_FIRED_AFTER(CurrentTriggerData->tg_event))
29+
if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
3030
elog(ERROR,"autoinc: must be fired before event");
3131

32-
if (TRIGGER_FIRED_BY_INSERT(CurrentTriggerData->tg_event))
33-
rettuple=CurrentTriggerData->tg_trigtuple;
34-
elseif (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
35-
rettuple=CurrentTriggerData->tg_newtuple;
32+
if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
33+
rettuple=trigdata->tg_trigtuple;
34+
elseif (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
35+
rettuple=trigdata->tg_newtuple;
3636
else
3737
elog(ERROR,"autoinc: can't process DELETE events");
3838

39-
rel=CurrentTriggerData->tg_relation;
39+
rel=trigdata->tg_relation;
4040
relname=SPI_getrelname(rel);
4141

42-
trigger=CurrentTriggerData->tg_trigger;
42+
trigger=trigdata->tg_trigger;
4343

4444
nargs=trigger->tgnargs;
4545
if (nargs <=0||nargs %2!=0)
@@ -48,8 +48,6 @@ autoinc()
4848
args=trigger->tgargs;
4949
tupdesc=rel->rd_att;
5050

51-
CurrentTriggerData=NULL;
52-
5351
chattrs= (int*)palloc(nargs /2*sizeof(int));
5452
newvals= (Datum*)palloc(nargs /2*sizeof(Datum));
5553

@@ -96,5 +94,5 @@ autoinc()
9694
pfree(chattrs);
9795
pfree(newvals);
9896

99-
return (rettuple);
97+
returnPointerGetDatum(rettuple);
10098
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp