PostgreSQL Source Code: contrib/spi/autoinc.c Source File (original) (raw)
1
2
3
5
13
15 .name = "autoinc",
16 .version = PG_VERSION
17);
18
20
23{
25 Trigger *trigger;
26 int nargs;
27 int *chattrs;
28 int chnattrs = 0;
29 Datum *newvals;
30 bool *newnulls;
31 char **args;
32 char *relname;
33 Relation rel;
35 TupleDesc tupdesc;
36 bool isnull;
37 int i;
38
40
41 elog(ERROR, "not fired by trigger manager");
43
44 elog(ERROR, "must be fired for row");
46
47 elog(ERROR, "must be fired before event");
48
53 else
54
55 elog(ERROR, "cannot process DELETE events");
56
59
61
63 if (nargs <= 0 || nargs % 2 != 0)
64
65 elog(ERROR, "autoinc (%s): even number gt 0 of arguments was expected", relname);
66
67 args = trigger->tgargs;
68 tupdesc = rel->rd_att;
69
70 chattrs = (int *) palloc(nargs / 2 * sizeof(int));
72 newnulls = (bool *) palloc(nargs / 2 * sizeof(bool));
73
75 {
79
82 (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
83 errmsg("\"%s\" has no attribute \"%s\"",
85
88 (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
89 errmsg("attribute \"%s\" of \"%s\" must be type INT4",
91
93
94 if (!isnull && val != 0)
95 {
96 i += 2;
97 continue;
98 }
99
100 i++;
101 chattrs[chnattrs] = attnum;
104
107 {
110 }
111 newnulls[chnattrs] = false;
113 chnattrs++;
114 i++;
115 }
116
117 if (chnattrs > 0)
118 {
120 chnattrs, chattrs,
121 newvals, newnulls);
122 }
123
128
130}
PG_MODULE_MAGIC_EXT(.name="autoinc",.version=PG_VERSION)
PG_FUNCTION_INFO_V1(autoinc)
Datum autoinc(PG_FUNCTION_ARGS)
#define CStringGetTextDatum(s)
Datum nextval(PG_FUNCTION_ARGS)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define DatumGetTextPP(X)
#define DirectFunctionCall1(func, arg1)
HeapTuple heap_modify_tuple_by_cols(HeapTuple tuple, TupleDesc tupleDesc, int nCols, const int *replCols, const Datum *replValues, const bool *replIsnull)
if(TABLE==NULL||TABLE_index==NULL)
void pfree(void *pointer)
static int64 DatumGetInt64(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
char * SPI_getrelname(Relation rel)
#define TRIGGER_FIRED_BEFORE(event)
#define CALLED_AS_TRIGGER(fcinfo)
#define TRIGGER_FIRED_FOR_ROW(event)
#define TRIGGER_FIRED_BY_INSERT(event)
#define TRIGGER_FIRED_BY_UPDATE(event)