summaryrefslogtreecommitdiff
path: root/contrib/fulltextindex
diff options
context:
space:
mode:
authorTom Lane2000-05-29 01:59:17 +0000
committerTom Lane2000-05-29 01:59:17 +0000
commit18952f67446da73f938d213b5225b99e95657837 (patch)
tree7ad26843000b8a17e798dafacbd29baf2d390fa1 /contrib/fulltextindex
parent147ccf5c8045c79a9c8194044359e140c9074ed7 (diff)
Second round of fmgr changes: triggers are now invoked in new style,
CurrentTriggerData is history.
Diffstat (limited to 'contrib/fulltextindex')
-rw-r--r--contrib/fulltextindex/README3
-rw-r--r--contrib/fulltextindex/fti.c46
-rw-r--r--contrib/fulltextindex/fticopy2
3 files changed, 25 insertions, 26 deletions
diff --git a/contrib/fulltextindex/README b/contrib/fulltextindex/README
index 36d611cf32..06850f7493 100644
--- a/contrib/fulltextindex/README
+++ b/contrib/fulltextindex/README
@@ -56,7 +56,8 @@ sub-string will fit.
The create the function that contains the trigger::
- create function fti() returns opaque as '/path/to/fti.so' language 'C';
+ create function fti() returns opaque as
+ '/path/to/fti.so' language 'newC';
And finally define the trigger on the 'cds' table:
diff --git a/contrib/fulltextindex/fti.c b/contrib/fulltextindex/fti.c
index 0291a48a27..aa5f066897 100644
--- a/contrib/fulltextindex/fti.c
+++ b/contrib/fulltextindex/fti.c
@@ -17,7 +17,7 @@
Example:
create function fti() returns opaque as
-'/home/boekhold/src/postgresql-6.2/contrib/fti/fti.so' language 'c';
+'/home/boekhold/src/postgresql-6.2/contrib/fti/fti.so' language 'newC';
create table title_fti (string varchar(25), id oid);
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
that can build the final query automatigally?
*/
-HeapTuple fti(void);
-char *breakup(char *, char *);
-bool is_stopword(char *);
+extern Datum fti(PG_FUNCTION_ARGS);
+static char *breakup(char *, char *);
+static bool is_stopword(char *);
-bool new_tuple = false;
+static bool new_tuple = false;
/* THIS LIST MUST BE IN SORTED ORDER, A BINARY SEARCH IS USED!!!! */
@@ -93,9 +93,10 @@ static int nDeletePlans = 0;
static EPlan *find_plan(char *ident, EPlan ** eplan, int *nplans);
/***********************************************************************/
-HeapTuple
-fti()
+Datum
+fti(PG_FUNCTION_ARGS)
{
+ TriggerData *trigdata = (TriggerData *) fcinfo->context;
Trigger *trigger; /* to get trigger name */
int nargs; /* # of arguments */
char **args; /* arguments */
@@ -119,32 +120,29 @@ fti()
* function\n"); fflush(debug);
*/
- if (!CurrentTriggerData)
- elog(ERROR, "Full Text Indexing: triggers are not initialized");
- if (TRIGGER_FIRED_FOR_STATEMENT(CurrentTriggerData->tg_event))
+ if (!CALLED_AS_TRIGGER(fcinfo))
+ elog(ERROR, "Full Text Indexing: not fired by trigger manager");
+ if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
elog(ERROR, "Full Text Indexing: can't process STATEMENT events");
- if (TRIGGER_FIRED_BEFORE(CurrentTriggerData->tg_event))
+ if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
elog(ERROR, "Full Text Indexing: must be fired AFTER event");
- if (TRIGGER_FIRED_BY_INSERT(CurrentTriggerData->tg_event))
+ if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
isinsert = true;
- if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
+ if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
{
isdelete = true;
isinsert = true;
}
- if (TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event))
+ if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
isdelete = true;
- trigger = CurrentTriggerData->tg_trigger;
- rel = CurrentTriggerData->tg_relation;
+ trigger = trigdata->tg_trigger;
+ rel = trigdata->tg_relation;
relname = SPI_getrelname(rel);
- rettuple = CurrentTriggerData->tg_trigtuple;
+ rettuple = trigdata->tg_trigtuple;
if (isdelete && isinsert) /* is an UPDATE */
- rettuple = CurrentTriggerData->tg_newtuple;
-
- CurrentTriggerData = NULL; /* invalidate 'normal' calls to this
- * function */
+ rettuple = trigdata->tg_newtuple;
if ((ret = SPI_connect()) < 0)
elog(ERROR, "Full Text Indexing: SPI_connect failed, returned %d\n", ret);
@@ -289,10 +287,10 @@ fti()
}
SPI_finish();
- return (rettuple);
+ return PointerGetDatum(rettuple);
}
-char *
+static char *
breakup(char *string, char *substring)
{
static char *last_start;
@@ -342,7 +340,7 @@ breakup(char *string, char *substring)
}
/* copied from src/backend/parser/keywords.c and adjusted for our situation*/
-bool
+static bool
is_stopword(char *text)
{
char **StopLow; /* for list of stop-words */
diff --git a/contrib/fulltextindex/fticopy b/contrib/fulltextindex/fticopy
index 02bf057e94..6b6d68e490 100644
--- a/contrib/fulltextindex/fticopy
+++ b/contrib/fulltextindex/fticopy
@@ -29,7 +29,7 @@
#
# create function fti() returns opaque as
# '/path/to/fti/file/fti.so'
-# language 'C';
+# language 'newC';
#
# create trigger my_fti_trigger after update or insert or delete
# on mytable