mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list
provided by Andrew.
This commit is contained in:
@ -1,13 +1,13 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* trigfuncs.c
|
||||
* Builtin functions for useful trigger support.
|
||||
* Builtin functions for useful trigger support.
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.6 2009/01/01 17:23:50 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.7 2009/06/11 14:49:04 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -27,61 +27,64 @@
|
||||
Datum
|
||||
suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
|
||||
{
|
||||
TriggerData *trigdata = (TriggerData *) fcinfo->context;
|
||||
HeapTuple newtuple, oldtuple, rettuple;
|
||||
HeapTupleHeader newheader, oldheader;
|
||||
TriggerData *trigdata = (TriggerData *) fcinfo->context;
|
||||
HeapTuple newtuple,
|
||||
oldtuple,
|
||||
rettuple;
|
||||
HeapTupleHeader newheader,
|
||||
oldheader;
|
||||
|
||||
/* make sure it's called as a trigger */
|
||||
if (!CALLED_AS_TRIGGER(fcinfo))
|
||||
ereport(ERROR,
|
||||
/* make sure it's called as a trigger */
|
||||
if (!CALLED_AS_TRIGGER(fcinfo))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
|
||||
errmsg("suppress_redundant_updates_trigger: must be called as trigger")));
|
||||
|
||||
/* and that it's called on update */
|
||||
if (! TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
|
||||
ereport(ERROR,
|
||||
|
||||
/* and that it's called on update */
|
||||
if (!TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
|
||||
errmsg("suppress_redundant_updates_trigger: must be called on update")));
|
||||
|
||||
/* and that it's called before update */
|
||||
if (! TRIGGER_FIRED_BEFORE(trigdata->tg_event))
|
||||
ereport(ERROR,
|
||||
/* and that it's called before update */
|
||||
if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
|
||||
errmsg("suppress_redundant_updates_trigger: must be called before update")));
|
||||
|
||||
/* and that it's called for each row */
|
||||
if (! TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
|
||||
ereport(ERROR,
|
||||
/* and that it's called for each row */
|
||||
if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
|
||||
errmsg("suppress_redundant_updates_trigger: must be called for each row")));
|
||||
|
||||
/* get tuple data, set default result */
|
||||
rettuple = newtuple = trigdata->tg_newtuple;
|
||||
rettuple = newtuple = trigdata->tg_newtuple;
|
||||
oldtuple = trigdata->tg_trigtuple;
|
||||
|
||||
newheader = newtuple->t_data;
|
||||
oldheader = oldtuple->t_data;
|
||||
|
||||
/*
|
||||
* We are called before the OID, if any, has been transcribed from the
|
||||
* old tuple to the new (in heap_update). To avoid a bogus compare
|
||||
* failure, copy the OID now. But check that someone didn't already put
|
||||
* another OID value into newtuple. (That's not actually possible at
|
||||
* present, but maybe someday.)
|
||||
* We are called before the OID, if any, has been transcribed from the old
|
||||
* tuple to the new (in heap_update). To avoid a bogus compare failure,
|
||||
* copy the OID now. But check that someone didn't already put another
|
||||
* OID value into newtuple. (That's not actually possible at present, but
|
||||
* maybe someday.)
|
||||
*/
|
||||
if (trigdata->tg_relation->rd_rel->relhasoids &&
|
||||
if (trigdata->tg_relation->rd_rel->relhasoids &&
|
||||
!OidIsValid(HeapTupleHeaderGetOid(newheader)))
|
||||
HeapTupleHeaderSetOid(newheader, HeapTupleHeaderGetOid(oldheader));
|
||||
|
||||
/* if the tuple payload is the same ... */
|
||||
if (newtuple->t_len == oldtuple->t_len &&
|
||||
if (newtuple->t_len == oldtuple->t_len &&
|
||||
newheader->t_hoff == oldheader->t_hoff &&
|
||||
(HeapTupleHeaderGetNatts(newheader) ==
|
||||
(HeapTupleHeaderGetNatts(newheader) ==
|
||||
HeapTupleHeaderGetNatts(oldheader)) &&
|
||||
((newheader->t_infomask & ~HEAP_XACT_MASK) ==
|
||||
((newheader->t_infomask & ~HEAP_XACT_MASK) ==
|
||||
(oldheader->t_infomask & ~HEAP_XACT_MASK)) &&
|
||||
memcmp(((char *)newheader) + offsetof(HeapTupleHeaderData, t_bits),
|
||||
((char *)oldheader) + offsetof(HeapTupleHeaderData, t_bits),
|
||||
memcmp(((char *) newheader) + offsetof(HeapTupleHeaderData, t_bits),
|
||||
((char *) oldheader) + offsetof(HeapTupleHeaderData, t_bits),
|
||||
newtuple->t_len - offsetof(HeapTupleHeaderData, t_bits)) == 0)
|
||||
{
|
||||
/* ... then suppress the update */
|
||||
|
Reference in New Issue
Block a user