X-Original-To: pgsql-interfaces-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E1D659FB21E for ; Fri, 28 Jul 2006 13:31:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 59983-08 for ; Fri, 28 Jul 2006 13:31:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 298EC9FA5BF for ; Fri, 28 Jul 2006 13:31:06 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mail009.ownmail.com (unknown [203.199.110.93]) by svr4.postgresql.org (Postfix) with ESMTP id 3069B5AFB53 for ; Fri, 28 Jul 2006 16:31:03 +0000 (GMT) Received: (from domains@localhost) by mail009.ownmail.com (8.12.11/8.12.10) id k6SGRwtM029266; Fri, 28 Jul 2006 21:57:58 +0530 Date: Fri, 28 Jul 2006 21:57:58 +0530 Message-Id: <200607281627.k6SGRwtM029266@mail009.ownmail.com> X-Originating-IP: 203.199.110.93 Reply-To: From: To: pgsql-interfaces@postgresql.org Subject: Re: SPI_getvalue gives a core dump MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.001 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, NO_REAL_NAME X-Spam-Level: ** Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200607/14 X-Sequence-Number: 6204 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: > > 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