~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/trigfuncs.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*-------------------------------------------------------------------------
2
2
 *
3
3
 * trigfuncs.c
4
 
 *    Builtin functions for useful trigger support.
 
4
 *        Builtin functions for useful trigger support.
5
5
 *
6
6
 *
7
7
 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
9
 *
10
 
 * $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.6 2009/01/01 17:23:50 momjian Exp $
 
10
 * $PostgreSQL: pgsql/src/backend/utils/adt/trigfuncs.c,v 1.7 2009/06/11 14:49:04 momjian Exp $
11
11
 *
12
12
 *-------------------------------------------------------------------------
13
13
 */
27
27
Datum
28
28
suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
29
29
{
30
 
    TriggerData *trigdata = (TriggerData *) fcinfo->context;
31
 
    HeapTuple   newtuple, oldtuple, rettuple;
32
 
        HeapTupleHeader newheader, oldheader;
 
30
        TriggerData *trigdata = (TriggerData *) fcinfo->context;
 
31
        HeapTuple       newtuple,
 
32
                                oldtuple,
 
33
                                rettuple;
 
34
        HeapTupleHeader newheader,
 
35
                                oldheader;
33
36
 
34
 
    /* make sure it's called as a trigger */
35
 
    if (!CALLED_AS_TRIGGER(fcinfo))
36
 
        ereport(ERROR,
 
37
        /* make sure it's called as a trigger */
 
38
        if (!CALLED_AS_TRIGGER(fcinfo))
 
39
                ereport(ERROR,
37
40
                                (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
38
41
                                 errmsg("suppress_redundant_updates_trigger: must be called as trigger")));
39
 
        
40
 
    /* and that it's called on update */
41
 
    if (! TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
42
 
        ereport(ERROR,
 
42
 
 
43
        /* and that it's called on update */
 
44
        if (!TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
 
45
                ereport(ERROR,
43
46
                                (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
44
47
                                 errmsg("suppress_redundant_updates_trigger: must be called on update")));
45
48
 
46
 
    /* and that it's called before update */
47
 
    if (! TRIGGER_FIRED_BEFORE(trigdata->tg_event))
48
 
        ereport(ERROR,
 
49
        /* and that it's called before update */
 
50
        if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
 
51
                ereport(ERROR,
49
52
                                (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
50
53
                                 errmsg("suppress_redundant_updates_trigger: must be called before update")));
51
54
 
52
 
    /* and that it's called for each row */
53
 
    if (! TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
54
 
        ereport(ERROR,
 
55
        /* and that it's called for each row */
 
56
        if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
 
57
                ereport(ERROR,
55
58
                                (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
56
59
                                 errmsg("suppress_redundant_updates_trigger: must be called for each row")));
57
60
 
58
61
        /* get tuple data, set default result */
59
 
        rettuple  = newtuple = trigdata->tg_newtuple;
 
62
        rettuple = newtuple = trigdata->tg_newtuple;
60
63
        oldtuple = trigdata->tg_trigtuple;
61
64
 
62
65
        newheader = newtuple->t_data;
63
66
        oldheader = oldtuple->t_data;
64
67
 
65
68
        /*
66
 
         * We are called before the OID, if any, has been transcribed from the
67
 
         * old tuple to the new (in heap_update).  To avoid a bogus compare
68
 
         * failure, copy the OID now.  But check that someone didn't already put
69
 
         * another OID value into newtuple.  (That's not actually possible at
70
 
         * present, but maybe someday.)
 
69
         * We are called before the OID, if any, has been transcribed from the old
 
70
         * tuple to the new (in heap_update).  To avoid a bogus compare failure,
 
71
         * copy the OID now.  But check that someone didn't already put another
 
72
         * OID value into newtuple.  (That's not actually possible at present, but
 
73
         * maybe someday.)
71
74
         */
72
 
        if (trigdata->tg_relation->rd_rel->relhasoids && 
 
75
        if (trigdata->tg_relation->rd_rel->relhasoids &&
73
76
                !OidIsValid(HeapTupleHeaderGetOid(newheader)))
74
77
                HeapTupleHeaderSetOid(newheader, HeapTupleHeaderGetOid(oldheader));
75
78
 
76
79
        /* if the tuple payload is the same ... */
77
 
    if (newtuple->t_len == oldtuple->t_len &&
 
80
        if (newtuple->t_len == oldtuple->t_len &&
78
81
                newheader->t_hoff == oldheader->t_hoff &&
79
 
                (HeapTupleHeaderGetNatts(newheader) == 
 
82
                (HeapTupleHeaderGetNatts(newheader) ==
80
83
                 HeapTupleHeaderGetNatts(oldheader)) &&
81
 
                ((newheader->t_infomask & ~HEAP_XACT_MASK) == 
 
84
                ((newheader->t_infomask & ~HEAP_XACT_MASK) ==
82
85
                 (oldheader->t_infomask & ~HEAP_XACT_MASK)) &&
83
 
                memcmp(((char *)newheader) + offsetof(HeapTupleHeaderData, t_bits),
84
 
                           ((char *)oldheader) + offsetof(HeapTupleHeaderData, t_bits),
 
86
                memcmp(((char *) newheader) + offsetof(HeapTupleHeaderData, t_bits),
 
87
                           ((char *) oldheader) + offsetof(HeapTupleHeaderData, t_bits),
85
88
                           newtuple->t_len - offsetof(HeapTupleHeaderData, t_bits)) == 0)
86
89
        {
87
90
                /* ... then suppress the update */