pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedSPI_getvalue gives a core dump
5+ messages / 2 participants
[nested] [flat]
* SPI_getvalue gives a core dump
@ 2006-07-28 15:35 vivek@staff.ownmail.com
0 siblings, 1 reply; 5+ messages in thread
From: vivek@staff.ownmail.com @ 2006-07-28 15:35 UTC (permalink / raw)
To: pgsql-interfaces
I am using postgresql:-
PostgreSQL 8.0.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.4
I am trying to trigger a function on insert. I get the following error:-
LOG: statement: INSERT INTO ast_cdr (calldate,clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) VALUES ('2006-07-28 20:35:14','"15554216325" <15554216325>','15554216325','889','from_box', 'SIP/15554216325-5914','SIP/69.54.75.50-da64','Playback','vivek/myfile'| noanswer',3,0,'NO ANSWER',3,'0','1154099114.198','vivek'
LOG: statement: SELECT count(*) FROM ast_cdr
CONTEXT: SQL statement "SELECT count(*) FROM ast_cdr"
LOG: server process (PID 5561) was terminated by signal 11
LOG: terminating any other active server processes
WARNING: terminating connection because of crash of another server process
DETAIL: The postmaster has command
ed this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
I tried executing this:-
SELECT count(*) FROM ast_cdr;
-[ RECORD 1 ]
count | 2
I dont know where am i going wrong. Here is the source.
TriggerData *trigdata = (TriggerData *) fcinfo->context;
TupleDesc tupdesc;
if (CALLED_AS_TRIGGER(fcinfo)) { ==================== it comes here and enters inside.
userfield=SPI_getvalue(trigdata->tg_trigtuple,tupdesc,17); ================== it fails here because i tried to get logs before this statement and it succeeded.
Please help this newbie.
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 gives a core dump
@ 2006-07-28 16:07 Tom Lane <tgl@sss.pgh.pa.us>
parent: vivek@staff.ownmail.com
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2006-07-28 16:07 UTC (permalink / raw)
To: vivek@staff.ownmail.com; +Cc: pgsql-interfaces
<vivek@staff.ownmail.com> writes:
> I dont know where am i going wrong. Here is the source.
> TriggerData *trigdata = (TriggerData *) fcinfo->context;
> TupleDesc tupdesc;
> if (CALLED_AS_TRIGGER(fcinfo)) { ==================== it comes here and enters inside.
> userfield=SPI_getvalue(trigdata->tg_trigtuple,tupdesc,17); ================== it fails here because i tried to get logs before this statement and it succeeded.
Wrong tupdesc maybe? You didn't show us what you are setting tupdesc
to.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SPI_getvalue gives a core dump
@ 2006-07-28 16:27 vivek@staff.ownmail.com
0 siblings, 1 reply; 5+ messages in thread
From: vivek@staff.ownmail.com @ 2006-07-28 16:27 UTC (permalink / raw)
To: pgsql-interfaces
This is what i set my tupdesc to. => tupdesc = trigdata->tg_relation->rd_att;
i am using the code like this. the do_log function to log the flow. it gives all correct until it reaches
the line :-
disposition=SPI_getvalue(trigdata->tg_trigtuple, tupdesc, 13);
do_log("Got disposition"); ======> it stops logging from here.
do_log("Entered the main trigger logic"); =========> success
if (TRIGGER_FIRED_BEFORE(trigdata->tg_event)) when = "before";
else when = "after ";
tupdesc = trigdata->tg_relation->rd_att;
if ((ret = SPI_connect()) < 0)
do_log("SPI_connect failed");
else {
sprintf(logs,"SPI_connect success, fired %s",when); ======> success
do_log(logs);
}
ret = SPI_exec("SELECT count(*) FROM ast_cdr", 0);
if (ret < 0){
sprintf(logs, "trigf (fired %s): SPI_exec returned %d", when, ret);
do_log(logs);
}
/* count(*) returns int8, so be careful to convert */
i = DatumGetInt64(SPI_getbinval(SPI_tuptable->vals[0], tupdesc, 1, &isnull));
sprintf(logs, "trigf (fired %s): there are %d rows in ast_cdr", when, i); ====> success
do_log(logs);
disposition=SPI_getvalue(trigdata->tg_trigtuple, tupdesc, 13); =====> failed.
do_log("Got disposition"); ===============> doesnot reach here.
With warm regards.
Vivek J. Joshi.
vivek@staff.ownmail.com
Trikon electronics Pvt. Ltd.
All science is either physics or stamp collecting.
-- Ernest Rutherford
Tom Lane wrote:
> ><vivek@staff.ownmail.com> writes:
>> I dont know where am i going wrong. Here is the source.
>
>> TriggerData *trigdata = (TriggerData *) fcinfo->context;
>> TupleDesc tupdesc;
>> if (CALLED_AS_TRIGGER(fcinfo)) { ==================== it comes here and
enters inside.
>> userfield=SPI_getvalue(trigdata->tg_trigtuple,tupdesc,17);
================== it fails here because i tried to get logs before this
statement and it succeeded.
>
>Wrong tupdesc maybe? You didn't show us what you are setting tupdesc
>to.
>
> regards, tom lane
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SPI_getvalue gives a core dump
@ 2006-07-28 16:38 Tom Lane <tgl@sss.pgh.pa.us>
parent: vivek@staff.ownmail.com
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2006-07-28 16:38 UTC (permalink / raw)
To: vivek@staff.ownmail.com; +Cc: pgsql-interfaces
<vivek@staff.ownmail.com> writes:
> i = DatumGetInt64(SPI_getbinval(SPI_tuptable->vals[0], tupdesc, 1, &isnull));
I think this is your problem: you're trying to use the wrong tupdesc to
retrieve from the SELECT count(*) result. SPI_tuptable->tupdesc would
work better there.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SPI_getvalue gives a core dump
@ 2006-07-28 17:02 vivek@staff.ownmail.com
0 siblings, 0 replies; 5+ messages in thread
From: vivek@staff.ownmail.com @ 2006-07-28 17:02 UTC (permalink / raw)
To: pgsql-interfaces
I have already tried it out. I tried the following:-
char *myval
1) i = DatumGetInt64(SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull));
2) myval=SPI_getvalue(trigdata->tg_trigtuple, tupdesc, 17);
3) myval=SPI_getvalue(trigdata->tg_trigtuple, trigdata->tg_relation->rd_att, 17);
4) myval=strdup(SPI_getvalue(trigdata->tg_trigtuple, trigdata->tg_relation->rd_att, 17));
5) if ((myval=SPI_getvalue(trigdata->tg_trigtuple, trigdata->tg_relation->rd_att, 17))==NULL) then, log and exit.
With warm regards.
Vivek J. Joshi.
vivek@staff.ownmail.com
Trikon electronics Pvt. Ltd.
All science is either physics or stamp collecting.
-- Ernest Rutherford
Tom Lane wrote:
> ><vivek@staff.ownmail.com> writes:
>> i = DatumGetInt64(SPI_getbinval(SPI_tuptable->vals[0],
tupdesc, 1, &isnull));
>
>I think this is your problem: you're trying to use the wrong tupdesc to
>retrieve from the SELECT count(*) result. SPI_tuptable->tupdesc would
>work better there.
>
> regards, tom lane
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2006-07-28 17:02 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-07-28 15:35 SPI_getvalue gives a core dump vivek@staff.ownmail.com
2006-07-28 16:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-07-28 16:27 Re: SPI_getvalue gives a core dump vivek@staff.ownmail.com
2006-07-28 16:38 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-07-28 17:02 Re: SPI_getvalue gives a core dump 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