Skip site navigation (1) Skip section navigation (2)

Problem with trigger function in C

From: "Joe Halpin" <jhalpin100(at)gmail(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Problem with trigger function in C
Date: 2008-10-28 19:34:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
I'm new at this and I apologize if I got the wrong list, but I'm
trying to write a trigger function in C which is linked in with
libxqilla and is supposed to run an xquery against some xml we have
stored in a column. I find that when the function is entered fcinfo is
null, which causes a segfault.

I copied the example trigger function from the documentation at I
added some debug output to tell that fcinfo is null.

I built the function by copying the makefile in the contrib directory
for the xml2 demo and modifying it a bit. Here's what I wound up with:

--- start ---
MODULE_big = xqueryTrigger
PG_CPPFLAGS = -I$(libpq_srcdir)
OBJS = xqueryTrigger.o
SHLIB_LINK = -L/usr/local/lib -lxqilla -lxerces-c-3.0 -lcrypto -lssl

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
subdir = contrib/xml2
top_builddir = ../..
include $(top_builddir)/src/
include $(top_srcdir)/contrib/
--- stop ---

Here's the trigger function (or at least as far as it gets)

--- start ---
#include "postgres.h"
#include "executor/spi.h"       /* this is what you need to work with SPI */
#include "commands/trigger.h"   /* ... and triggers */
#include <fmgr.h>


typedef void*(*memFunc)(unsigned int sz);
extern int runQuery(const char *qry, const char *xml, char **result,
memFunc allocator);

extern Datum xqueryTrigger(PG_FUNCTION_ARGS);


void *memAllocator(unsigned int);
Datum xquerytrigger(PG_FUNCTION_ARGS);

void *memAllocator(unsigned int sz)
    return palloc(sz);

    TriggerData *trigdata;
    TupleDesc   tupdesc;
    HeapTuple   rettuple;
    char       *when;
    bool        checknull;
    bool        isnull;
    int         ret, i;
    char       *status;

    elog(INFO, "Entering xquerytrigger()");
    elog(INFO, "getting TriggerData...");
    elog(INFO, "fcinfo = %p", fcinfo);
    elog(INFO, "fcinfo->context = %p", fcinfo->context);
    trigdata = (TriggerData *) fcinfo->context;
--- stop ---

Any advice would be appreciated.




pgsql-interfaces by date

Next:From: Tom LaneDate: 2008-10-28 20:01:53
Subject: Re: Problem with trigger function in C
Previous:From: Jeroen VermeulenDate: 2008-10-22 05:27:28
Subject: Re: Retrieving points, arrays, ... with libpq

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group