pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedSPI_getvalue fails
5+ messages / 2 participants
[nested] [flat]
* SPI_getvalue fails
@ 2006-07-31 06:59 vivek@staff.ownmail.com
2006-07-31 12:52 ` Re: SPI_getvalue fails Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 5+ messages in thread
From: vivek@staff.ownmail.com @ 2006-07-31 06:59 UTC (permalink / raw)
To: pgsql-interfaces
Hello group,
I get a coredump if I try to use SPI_getvalue. Upon writing some logs, I see that postgresql gets the insert statement properly with all the values non null but the variable
trigdata->tg_trigtuple
is NULL. I am not able to figure out why it happens so.
I would be very grateful if you can help me with this friends.
With warm regards.
Vivek J. Joshi.
vivek@staff.ownmail.com
Trikon electronics Pvt. Ltd.
All science is either physics or stamp collecting.
-- Ernest Rutherford
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SPI_getvalue fails
2006-07-31 06:59 SPI_getvalue fails vivek@staff.ownmail.com
@ 2006-07-31 12:52 ` Michael Fuhr <mike@fuhr.org>
0 siblings, 0 replies; 5+ messages in thread
From: Michael Fuhr @ 2006-07-31 12:52 UTC (permalink / raw)
To: vivek@staff.ownmail.com; +Cc: pgsql-interfaces
On Mon, Jul 31, 2006 at 12:29:25PM +0530, vivek@staff.ownmail.com wrote:
> I get a coredump if I try to use SPI_getvalue. Upon writing some
> logs, I see that postgresql gets the insert statement properly
> with all the values non null but the variable trigdata->tg_trigtuple
> is NULL. I am not able to figure out why it happens so.
The connection between trigdata->tg_trigtuple being NULL and
SPI_getvalue() causing a core dump isn't clear from what you've
written. It sounds like you're writing a C function that's called
via a trigger -- is that correct? Could you post the CREATE TRIGGER
statement and the function's code?
--
Michael Fuhr
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SPI_getvalue fails
@ 2006-07-31 13:01 vivek@staff.ownmail.com
2006-07-31 13:29 ` Re: SPI_getvalue fails Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 5+ messages in thread
From: vivek@staff.ownmail.com @ 2006-07-31 13:01 UTC (permalink / raw)
To: pgsql-interfaces
Here is the code:-
#include <stdio.h>
#include "postgres.h"
#include "executor/spi.h"
#include "commands/trigger.h"
#include <math.h>
#include <sys/time.h>
#include <time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <stddef.h>
#include <dirent.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
extern Datum trigast(PG_FUNCTION_ARGS);
extern char **environ;
int do_log(char *log)
{
FILE *fp=fopen("/home/vivek/logs/trig.log","a");
if (fp)
{
time_t t = time(NULL);
struct tm *c_date = localtime(&t);
char *t_now=strdup(asctime(c_date));
t_now[strlen(t_now)-1]=0;
fprintf(fp,"%s-trigfaxes-%s\n",t_now,log);
fclose(fp);
return 1;
}
return -1;
}
PG_FUNCTION_INFO_V1(trigast);
Datum
trigast(PG_FUNCTION_ARGS)
{
do_log("STARTING TRIGGER");
HeapTuple rettuple;
HeapTuple trigtuple;
TupleDesc tupdesc;
int ret, i;
bool isnull;
char *disposition; //13
char *when;
char logs[1024];
do_log(" Checking fcinfo");
if (CALLED_AS_TRIGGER(fcinfo)) {
TriggerData *trigdata = (TriggerData *) fcinfo->context;
SPI_connect();
do_log("GOT TRIGTUPLE");
rettuple = trigdata->tg_trigtuple;
char *relation=SPI_getrelname(trigdata->tg_relation);
sprintf(logs,"Relation is %s", relation);
do_log(logs);
trigtuple = trigdata->tg_trigtuple;
tupdesc = trigdata->tg_relation->rd_att;
if( tupdesc == NULL || trigtuple == NULL ){
do_log("tupdesc OR trigtuple == NULL" );
if( tupdesc == NULL )
do_log("tupdesc is NULL" );
if( trigtuple == NULL )
do_log( "trigtuple is NULL" );
}
else
do_log("tupdesc && trigtuple ARE NOT NULL" );
do_log("Starting to get values");
disposition=SPI_getvalue(trigtuple, tupdesc,13);
sprintf(logs, "value is %s", disposition);
do_log(logs); // doesnot reach here.
}
SPI_finish();
return PointerGetDatum(rettuple);
}
/*
logs are:-
Mon Jul 31 18:20:12 2006-trigfaxes-STARTING TRIGGER
Mon Jul 31 18:20:12 2006-trigfaxes- Checking fcinfo
Mon Jul 31 18:20:12 2006-trigfaxes-GOT TRIGTUPLE
Mon Jul 31 18:20:12 2006-trigfaxes-Relation is ast_cdr
Mon Jul 31 18:20:12 2006-trigfaxes-tupdesc OR trigtuple == NULL
Mon Jul 31 18:20:12 2006-trigfaxes-trigtuple is NULL
Mon Jul 31 18:20:12 2006-trigfaxes-Starting to get values
*/
/*
gdb shows:-
Program received signal SIGSEGV, Segmentation fault.
0x08121f46 in SPI_getvalue ()
(gdb) bt
#0 0x08121f46 in SPI_getvalue ()
*/
With warm regards.
Vivek J. Joshi.
vivek@staff.ownmail.com
Trikon electronics Pvt. Ltd.
All science is either physics or stamp collecting.
-- Ernest Rutherford
Michael Fuhr wrote:
> >On Mon, Jul 31, 2006 at 12:29:25PM +0530, vivek@staff.ownmail.com wrote:
>> I get a coredump if I try to use SPI_getvalue. Upon writing some
>> logs, I see that postgresql gets the insert statement properly
>> with all the values non null but the variable trigdata->tg_trigtuple
>> is NULL. I am not able to figure out why it happens so.
>
>The connection between trigdata->tg_trigtuple being NULL and
>SPI_getvalue() causing a core dump isn't clear from what you've
>written. It sounds like you're writing a C function that's called
>via a trigger -- is that correct? Could you post the CREATE TRIGGER
>statement and the function's code?
>
>--
>Michael Fuhr
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: explain analyze is your friend
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SPI_getvalue fails
2006-07-31 13:01 Re: SPI_getvalue fails vivek@staff.ownmail.com
@ 2006-07-31 13:29 ` Michael Fuhr <mike@fuhr.org>
0 siblings, 0 replies; 5+ messages in thread
From: Michael Fuhr @ 2006-07-31 13:29 UTC (permalink / raw)
To: vivek@staff.ownmail.com; +Cc: pgsql-interfaces
On Mon, Jul 31, 2006 at 06:31:54PM +0530, vivek@staff.ownmail.com wrote:
> Here is the code:-
Could you post the CREATE TRIGGER statement? tg_trigtuple would
be NULL if you're using a statement-level trigger instead of a
row-level trigger.
--
Michael Fuhr
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SPI_getvalue fails
@ 2006-07-31 13:27 vivek@staff.ownmail.com
0 siblings, 0 replies; 5+ messages in thread
From: vivek@staff.ownmail.com @ 2006-07-31 13:27 UTC (permalink / raw)
To: pgsql-interfaces
Thanks friends, solved it.
added a FOR EACH ROW and it worked.
Thanks for all your support
With warm regards.
Vivek J. Joshi.
vivek@staff.ownmail.com
Trikon electronics Pvt. Ltd.
All science is either physics or stamp collecting.
-- Ernest Rutherford
vivek@staff.ownmail.com wrote:
> >Here is the code:-
>
>#include <stdio.h>
>#include "postgres.h"
>#include "executor/spi.h"
>#include "commands/trigger.h"
>#include <math.h>
>#include <sys/time.h>
>#include <time.h>
>#include <sys/types.h>
>#include <sys/wait.h>
>#include <unistd.h>
>#include <errno.h>
>#include <stddef.h>
>#include <dirent.h>
>
>#include <fcntl.h>
>#include <stdlib.h>
>#include <string.h>
>
>extern Datum trigast(PG_FUNCTION_ARGS);
>extern char **environ;
>
>int do_log(char *log)
>{
> FILE *fp=fopen("/home/vivek/logs/trig.log","a");
> if (fp)
> {
> time_t t = time(NULL);
> struct tm *c_date = localtime(&t);
> char *t_now=strdup(asctime(c_date));
> t_now[strlen(t_now)-1]=0;
> fprintf(fp,"%s-trigfaxes-%s\n",t_now,log);
> fclose(fp);
> return 1;
> }
> return -1;
>}
>
>
>PG_FUNCTION_INFO_V1(trigast);
>Datum
>trigast(PG_FUNCTION_ARGS)
>{
> do_log("STARTING TRIGGER");
> HeapTuple rettuple;
> HeapTuple trigtuple;
> TupleDesc tupdesc;
> int ret, i;
> bool isnull;
> char *disposition; //13
> char *when;
> char logs[1024];
>
> do_log(" Checking fcinfo");
> if (CALLED_AS_TRIGGER(fcinfo)) {
> TriggerData *trigdata = (TriggerData *) fcinfo->context;
> SPI_connect();
>
> do_log("GOT TRIGTUPLE");
>
> rettuple = trigdata->tg_trigtuple;
>
> char *relation=SPI_getrelname(trigdata->tg_relation);
> sprintf(logs,"Relation is %s", relation);
> do_log(logs);
>
> trigtuple = trigdata->tg_trigtuple;
> tupdesc = trigdata->tg_relation->rd_att;
>
> if( tupdesc == NULL || trigtuple == NULL ){
> do_log("tupdesc OR trigtuple == NULL" );
> if( tupdesc == NULL )
> do_log("tupdesc is NULL" );
> if( trigtuple == NULL )
> do_log( "trigtuple is NULL" );
> }
> else
> do_log("tupdesc && trigtuple ARE NOT NULL" );
>
>
> do_log("Starting to get values");
>
> disposition=SPI_getvalue(trigtuple, tupdesc,13);
> sprintf(logs, "value is %s", disposition);
> do_log(logs); // doesnot reach here.
>
> }
> SPI_finish();
> return PointerGetDatum(rettuple);
>
>}
>
>/*
>logs are:-
>Mon Jul 31 18:20:12 2006-trigfaxes-STARTING TRIGGER
>Mon Jul 31 18:20:12 2006-trigfaxes- Checking fcinfo
>Mon Jul 31 18:20:12 2006-trigfaxes-GOT TRIGTUPLE
>Mon Jul 31 18:20:12 2006-trigfaxes-Relation is ast_cdr
>Mon Jul 31 18:20:12 2006-trigfaxes-tupdesc OR trigtuple == NULL
>Mon Jul 31 18:20:12 2006-trigfaxes-trigtuple is NULL
>Mon Jul 31 18:20:12 2006-trigfaxes-Starting to get values
>*/
>
>/*
>gdb shows:-
>Program received signal SIGSEGV, Segmentation fault.
>0x08121f46 in SPI_getvalue ()
>(gdb) bt
>#0 0x08121f46 in SPI_getvalue ()
>*/
>
>
>
>
>With warm regards.
>
>Vivek J. Joshi.
>
>vivek@staff.ownmail.com
>Trikon electronics Pvt. Ltd.
>
>All science is either physics or stamp collecting.
> -- Ernest Rutherford
>
>
>
>Michael Fuhr wrote:
>> >On Mon, Jul 31, 2006 at 12:29:25PM +0530, vivek@staff.ownmail.com wrote:
>>> I get a coredump if I try to use SPI_getvalue. Upon writing some
>>> logs, I see that postgresql gets the insert statement properly
>>> with all the values non null but the variable trigdata->tg_trigtuple
>>> is NULL. I am not able to figure out why it happens so.
>>
>>The connection between trigdata->tg_trigtuple being NULL and
>>SPI_getvalue() causing a core dump isn't clear from what you've
>>written. It sounds like you're writing a C function that's called
>>via a trigger -- is that correct? Could you post the CREATE TRIGGER
>>statement and the function's code?
>>
>>--
>>Michael Fuhr
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 6: explain analyze is your friend
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: Don't 'kill -9' the postmaster
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2006-07-31 13:29 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-07-31 06:59 SPI_getvalue fails vivek@staff.ownmail.com
2006-07-31 12:52 ` Michael Fuhr <mike@fuhr.org>
2006-07-31 13:01 Re: SPI_getvalue fails vivek@staff.ownmail.com
2006-07-31 13:29 ` Michael Fuhr <mike@fuhr.org>
2006-07-31 13:27 Re: SPI_getvalue fails vivek@staff.ownmail.com
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox