mirror of
https://github.com/postgres/postgres.git
synced 2025-11-25 12:03:53 +03:00
Desultorily enclose programlisting tags in CDATA, to get rid of some obnoxious
SGML-escaping.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.52 2008/03/28 00:21:55 tgl Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.53 2008/12/07 23:46:39 alvherre Exp $ -->
|
||||
|
||||
<chapter id="triggers">
|
||||
<title>Triggers</title>
|
||||
@@ -559,7 +559,7 @@ CREATE TABLE ttest (
|
||||
|
||||
<para>
|
||||
This is the source code of the trigger function:
|
||||
<programlisting>
|
||||
<programlisting><![CDATA[
|
||||
#include "postgres.h"
|
||||
#include "executor/spi.h" /* this is what you need to work with SPI */
|
||||
#include "commands/trigger.h" /* ... and triggers */
|
||||
@@ -571,7 +571,7 @@ PG_FUNCTION_INFO_V1(trigf);
|
||||
Datum
|
||||
trigf(PG_FUNCTION_ARGS)
|
||||
{
|
||||
TriggerData *trigdata = (TriggerData *) fcinfo->context;
|
||||
TriggerData *trigdata = (TriggerData *) fcinfo->context;
|
||||
TupleDesc tupdesc;
|
||||
HeapTuple rettuple;
|
||||
char *when;
|
||||
@@ -584,38 +584,38 @@ trigf(PG_FUNCTION_ARGS)
|
||||
elog(ERROR, "trigf: not called by trigger manager");
|
||||
|
||||
/* tuple to return to executor */
|
||||
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
|
||||
rettuple = trigdata->tg_newtuple;
|
||||
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
|
||||
rettuple = trigdata->tg_newtuple;
|
||||
else
|
||||
rettuple = trigdata->tg_trigtuple;
|
||||
rettuple = trigdata->tg_trigtuple;
|
||||
|
||||
/* check for null values */
|
||||
if (!TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)
|
||||
&& TRIGGER_FIRED_BEFORE(trigdata->tg_event))
|
||||
if (!TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)
|
||||
&& TRIGGER_FIRED_BEFORE(trigdata->tg_event))
|
||||
checknull = true;
|
||||
|
||||
if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
|
||||
if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
|
||||
when = "before";
|
||||
else
|
||||
when = "after ";
|
||||
|
||||
tupdesc = trigdata->tg_relation->rd_att;
|
||||
tupdesc = trigdata->tg_relation->rd_att;
|
||||
|
||||
/* connect to SPI manager */
|
||||
if ((ret = SPI_connect()) < 0)
|
||||
if ((ret = SPI_connect()) < 0)
|
||||
elog(INFO, "trigf (fired %s): SPI_connect returned %d", when, ret);
|
||||
|
||||
/* get number of rows in table */
|
||||
ret = SPI_exec("SELECT count(*) FROM ttest", 0);
|
||||
|
||||
if (ret < 0)
|
||||
if (ret < 0)
|
||||
elog(NOTICE, "trigf (fired %s): SPI_exec returned %d", when, ret);
|
||||
|
||||
/* count(*) returns int8, so be careful to convert */
|
||||
i = DatumGetInt64(SPI_getbinval(SPI_tuptable->vals[0],
|
||||
SPI_tuptable->tupdesc,
|
||||
i = DatumGetInt64(SPI_getbinval(SPI_tuptable->vals[0],
|
||||
SPI_tuptable->tupdesc,
|
||||
1,
|
||||
&isnull));
|
||||
&isnull));
|
||||
|
||||
elog (INFO, "trigf (fired %s): there are %d rows in ttest", when, i);
|
||||
|
||||
@@ -623,13 +623,14 @@ trigf(PG_FUNCTION_ARGS)
|
||||
|
||||
if (checknull)
|
||||
{
|
||||
SPI_getbinval(rettuple, tupdesc, 1, &isnull);
|
||||
SPI_getbinval(rettuple, tupdesc, 1, &isnull);
|
||||
if (isnull)
|
||||
rettuple = NULL;
|
||||
}
|
||||
|
||||
return PointerGetDatum(rettuple);
|
||||
}
|
||||
]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user