File: common.h

package info (click to toggle)
pgq 3.2.6-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 836 kB
  • sloc: sql: 3,412; ansic: 1,990; python: 302; makefile: 89; sh: 2
file content (109 lines) | stat: -rw-r--r-- 2,500 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#if PG_VERSION_NUM < 100000
/* from src/include/access/tupdesc.h, introduced in 2cd708452 */
#define TupleDescAttr(tupdesc, i) ((tupdesc)->attrs[(i)])
#endif

enum PgqFields {
	EV_TYPE = 0,
	EV_DATA,
	EV_EXTRA1,
	EV_EXTRA2,
	EV_EXTRA3,
	EV_EXTRA4,
	EV_WHEN,
	EV_NFIELDS
};

/*
 * Per-event temporary data.
 */
struct PgqTriggerEvent {
	char op_type;
	const char *op_type_str;

	/* overridable fields */
	// fixme: check proper usage
	const char *table_name;
	const char *queue_name;
	const char *pkey_list;

	/* no cache for old-style args */
	const char *attkind;
	int attkind_len;

	/* cached per-table info */
	struct PgqTableInfo *info;

	/* cached per-trigger args */
	struct PgqTriggerInfo *tgargs;

	/* current event data */
	TriggerData *tgdata;

	/* result fields */
	StringInfo field[EV_NFIELDS];

	/* if 'when=' query fails */
	bool skip_event;
};
typedef struct PgqTriggerEvent PgqTriggerEvent;

/*
 * Per trigger cached info, stored under table cache,
 * so that invalidate can drop it.
 */
struct PgqTriggerInfo {
	struct PgqTriggerInfo *next;
	Oid tgoid;
	bool finalized;

	bool skip;
	bool backup;
	bool custom_fields;
	bool deny;

	const char *ignore_list;
	const char *pkey_list;

	struct QueryBuilder *query[EV_NFIELDS];
};

/*
 * Per-table cached info.
 *
 * Per-trigger info should be cached under tg_cache.
 */
struct PgqTableInfo {
	Oid reloid;		/* must be first, used by htab */
	int n_pkeys;		/* number of pkeys */
	const char *pkey_list;	/* pk column name list */
	int *pkey_attno;	/* pk column positions */
	char *table_name;	/* schema-quelified table name */
	int invalid;		/* set if the info was invalidated */
	const char *json_info;

	struct PgqTriggerInfo *tg_cache;
};

/* common.c */
void pgq_prepare_event(struct PgqTriggerEvent *ev, TriggerData *tg, bool newstyle);
void pgq_simple_insert(const char *queue_name, Datum ev_type, Datum ev_data,
		       Datum ev_extra1, Datum ev_extra2, Datum ev_extra3, Datum ev_extra4);
bool pgqtriga_skip_col(PgqTriggerEvent *ev, int i, int attkind_idx);
bool pgqtriga_is_pkey(PgqTriggerEvent *ev, int i, int attkind_idx);
void pgq_insert_tg_event(PgqTriggerEvent *ev);

bool pgq_is_logging_disabled(void);

/* makesql.c */
int pgqtriga_make_sql(PgqTriggerEvent *ev, StringInfo sql);

/* logutriga.c */
void pgq_urlenc_row(PgqTriggerEvent *ev, HeapTuple row, StringInfo buf);

int pgq_is_interesting_change(PgqTriggerEvent *ev, TriggerData *tg);

#ifndef TRIGGER_FIRED_BY_TRUNCATE
#define TRIGGER_FIRED_BY_TRUNCATE(tg)	0
#endif