-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpg_catcheck.h
196 lines (169 loc) · 5.85 KB
/
pg_catcheck.h
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*-------------------------------------------------------------------------
*
* pg_catcheck.h
*
* Functions and data structures for catalog integrity checking.
*
*-------------------------------------------------------------------------
*/
#ifndef PGCATCHECK_H
#define PGCATCHECK_H
#include "libpq-fe.h" /* for PGresult */
#include "compat.h"
/* Forward declarations. */
struct pgrhash;
typedef struct pgrhash pgrhash;
struct pg_catalog_table;
typedef struct pg_catalog_table pg_catalog_table;
/* Tri-value logic for handling table and column selection. */
enum trivalue
{
TRI_DEFAULT,
TRI_NO,
TRI_YES
};
/* Defined check types. */
typedef enum checktype
{
CHECK_ATTNUM,
CHECK_OID_REFERENCE,
CHECK_OID_VECTOR_REFERENCE,
CHECK_OID_ARRAY_REFERENCE,
CHECK_DEPENDENCY_CLASS_ID,
CHECK_DEPENDENCY_ID,
CHECK_DEPENDENCY_SUBID,
CHECK_RELNATTS,
} checktype;
/* Generic catalog check structure. */
typedef struct pg_catalog_check
{
checktype type;
} pg_catalog_check;
/* Specialization of pg_catalog_check for the various types of OID checks. */
typedef struct pg_catalog_check_oid
{
checktype type;
bool zero_oid_ok;
char *oid_references_table;
} pg_catalog_check_oid;
/* Everything we need to check a catalog column. */
typedef struct pg_catalog_column
{
/* These columns are listed in definitions.c */
char *name;
char *cast;
int minimum_version;
int maximum_version;
bool is_edb_only;
bool is_key_column;
bool is_display_column;
void *check; /* some kind of pg_catalog_check object */
/* These columns are populated at runtime. */
bool available;
enum trivalue checked;
bool needed;
void *check_private; /* workspace for individual checks */
int result_column; /* result column number */
} pg_catalog_column;
/* Everything we need to check an entire catalog table. */
struct pg_catalog_table
{
/* These columns are listed in definitions.c */
char *table_name;
pg_catalog_column *cols;
/* These columns are populated at runtime. */
bool available; /* OK for this version? */
enum trivalue checked;
bool needs_load; /* Still needs to be loaded? */
bool needs_check; /* Still needs to be checked? */
PGresult *data; /* Table data. */
pgrhash *ht; /* Hash of table data. */
int num_needs; /* # of tables we depend on. */
int num_needs_allocated; /* Allocated slots for same. */
pg_catalog_table **needs; /* Array of tables we depend on. */
int num_needed_by; /* # of tables depending on us. */
int num_needed_by_allocated; /* Allocated slots for same. */
pg_catalog_table **needed_by; /* Array of tables depending on us. */
};
/* Array of tables known to this tool. */
extern struct pg_catalog_table pg_catalog_tables[];
/* Identifying characteristics of the database to be checked. */
extern int remote_version; /* Version number. */
extern bool remote_is_edb; /* Is it an EDB database? */
extern char *database_oid; /* Database OID, if known. */
/* pg_catcheck.c */
extern pg_catalog_table *find_table_by_name(char *table_name);
extern pg_catalog_column *find_column_by_name(pg_catalog_table *, char *);
extern void add_table_dependency(pg_catalog_table *needs,
pg_catalog_table *needed_by);
/* check_attribute.c */
extern void prepare_to_check_attnum(pg_catalog_table *tab,
pg_catalog_column *tabcol);
extern void check_attnum(pg_catalog_table *tab, pg_catalog_column *tabcol,
int rownum);
/* check_class.c */
extern void prepare_to_check_relnatts(pg_catalog_table *tab,
pg_catalog_column *tabcol);
extern void check_relnatts(pg_catalog_table *tab, pg_catalog_column *tabcol,
int rownum);
/* check_depend.c */
extern void prepare_to_check_dependency_class_id(pg_catalog_table *tab,
pg_catalog_column *tabcol);
extern void prepare_to_check_dependency_id(pg_catalog_table *tab,
pg_catalog_column *tabcol);
extern void prepare_to_check_dependency_subid(pg_catalog_table *tab,
pg_catalog_column *tabcol);
extern void check_dependency_class_id(pg_catalog_table *tab,
pg_catalog_column *tabcol, int rownum);
extern void check_dependency_id(pg_catalog_table *tab,
pg_catalog_column *tabcol, int rownum);
extern void check_dependency_subid(pg_catalog_table *tab,
pg_catalog_column *tabcol, int rownum);
/* check_oids.c */
extern void prepare_to_check_oid_reference(pg_catalog_table *tab,
pg_catalog_column *tabcol);
extern void check_oid_reference(pg_catalog_table *tab,
pg_catalog_column *tabcol, int rownum);
/* select_from_relations.c */
extern void prepare_to_select_from_relations(void);
extern void perform_select_from_relations(PGconn *conn);
/* log.c */
typedef enum pgcc_severity
{
PGCC_DEBUG, /* Debugging messages for developers. */
PGCC_VERBOSE, /* Verbose messages. */
PGCC_PROGRESS, /* Progress messages. */
PGCC_NOTICE, /* Database inconsistencies. */
PGCC_WARNING, /* Warnings other than inconsistencies. */
PGCC_ERROR, /* Serious but not fatal errors. */
PGCC_FATAL /* Fatal errors. */
} pgcc_severity;
extern bool quiet;
extern int verbose;
#if PG_VERSION_NUM < 90500
extern void
pgcc_log(pgcc_severity sev, char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
extern void
pgcc_report(pg_catalog_table *tab, pg_catalog_column *tabcol,
int rownum, char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 4, 5)));
#else
extern void
pgcc_log(pgcc_severity sev, char *fmt,...)
pg_attribute_printf(2, 3);
extern void
pgcc_report(pg_catalog_table *tab, pg_catalog_column *tabcol,
int rownum, char *fmt,...)
pg_attribute_printf(4, 5);
#endif
extern void pgcc_log_completion(void);
#ifndef PG_USED_FOR_ASSERTS_ONLY
#define PG_USED_FOR_ASSERTS_ONLY
#endif
/* pgrhash.c */
#define MAX_KEY_COLS 10
extern pgrhash *pgrhash_create(PGresult *result, int nkeycols, int *keycols);
extern int pgrhash_get(pgrhash *ht, char **keyvals);
extern int pgrhash_insert(pgrhash *ht, int rownum);
#endif /* PGCATCHECK_H */