]> granicus.if.org Git - postgresql/blob - src/bin/pg_dump/pg_dump.h
Be more wary about mixed-case database names and user names. Get
[postgresql] / src / bin / pg_dump / pg_dump.h
1 /*-------------------------------------------------------------------------
2  *
3  * pg_dump.h
4  *        header file for the pg_dump utility
5  *
6  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: pg_dump.h,v 1.78 2002/02/11 00:18:20 tgl Exp $
10  *
11  * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
12  *
13  *       - Fixed dumpTable output to output lengths for char and varchar types!
14  *       - Added single. quote to twin single quote expansion for 'insert' string
15  *         mode.
16  *
17  * Modifications - 6/1/97 - igor@sba.miami.edu
18  * - Added extern's for the functions that clear allocated memory
19  *       in pg_dump.c
20  *
21  * Modifications - 14-Sep-2000 - pjw@rhyme.com.au
22  *      -       Added typedefn fields to typeinfo and relinfo
23  *      -       Added enum for findTypeByOid to allow special handling of
24  *              '0' OID.
25  *
26  *-------------------------------------------------------------------------
27  */
28
29 #ifndef PG_DUMP_H
30 #define PG_DUMP_H
31
32 #include "pg_backup.h"
33 #include "pqexpbuffer.h"
34
35 /* The data structures used to store system catalog information */
36
37 typedef struct _typeInfo
38 {
39         char       *oid;
40         char       *typowner;
41         char       *typname;
42         char       *typlen;
43         char       *typprtlen;
44         char       *typinput;
45         char       *typoutput;
46         char       *typreceive;
47         char       *typsend;
48         char       *typelem;
49         char       *typdelim;
50         char       *typdefault;
51         char       *typrelid;
52         char       *typalign;
53         char       *typstorage;
54         char       *usename;
55         char       *typedefn;
56         int                     passedbyvalue;
57         int                     isArray;
58         int                     isDefined;
59 } TypeInfo;
60
61 typedef struct _funcInfo
62 {
63         char       *oid;
64         char       *proname;
65         char       *proowner;
66         Oid                     lang;
67         int                     nargs;
68         char       *argtypes[FUNC_MAX_ARGS];
69         char       *prorettype;
70         int                     retset;                 /* 1 if the function returns a set, else 0 */
71         char       *prosrc;
72         char       *probin;
73         char       *usename;
74         int                     iscachable;             /* Attr */
75         int                     isstrict;               /* Attr */
76         int                     dumped;                 /* 1 if already dumped */
77 } FuncInfo;
78
79 typedef struct _trigInfo
80 {
81         char       *oid;
82         char       *tgname;
83         char       *tgsrc;
84         char       *tgdel;
85         char       *tgcomment;
86 } TrigInfo;
87
88 typedef struct _tableInfo
89 {
90         char       *oid;
91         char       *relname;
92         char       *relacl;
93         char       *viewdef;
94         char       *viewoid;            /* OID of view - should be >= oid of table
95                                                                  * important because views may be
96                                                                  * constructed manually from rules, and
97                                                                  * rule may ref things created after the
98                                                                  * base table was created. */
99         char            relkind;
100         bool            sequence;               /* this is redundant with relkind... */
101         bool            hasindex;               /* does it have any indexes? */
102         bool            hasoids;                /* does it have OIDs? */
103         int                     numatts;                /* number of attributes */
104         int                *inhAttrs;           /* an array of flags, one for each
105                                                                  * attribute if the value is 1, then this
106                                                                  * attribute is an inherited attribute */
107         int                *inhAttrDef;         /* Flags indicating if attrdef is
108                                                                  * inherited */
109         int                *inhNotNull;         /* Flags indicating if NOT NULL in
110                                                                  * inherited */
111         char      **attnames;           /* the attribute names */
112         char      **atttypedefns;       /* formatted column type definitions */
113         char      **typnames;           /* fill out attributes */
114         bool       *notnull;            /* Not null constraints of an attribute */
115         char      **adef_expr;          /* DEFAULT expressions */
116         int                     numParents;             /* number of (immediate) parent
117                                                                  * supertables */
118         char      **parentRels;         /* names of parent relations, NULL if
119                                                                  * numParents == 0 */
120         char      **out_attnames;       /* the attribute names, in the order they
121                                                                  * would be in, when the table is created
122                                                                  * in the target query language. this is
123                                                                  * needed because the SQL tables will not
124                                                                  * have the same order of attributes as
125                                                                  * the POSTQUEL tables */
126         int                *atttypmod;          /* type-specific type modifier */
127         char       *usename;
128         int                     ncheck;                 /* # of CHECK expressions */
129         char      **check_expr;         /* [CONSTRAINT name] CHECK expressions */
130         int                     ntrig;                  /* # of triggers */
131         TrigInfo   *triggers;           /* Triggers on the table */
132         char       *pkIndexOid;         /* Primary Key index OID */
133         char       *primary_key_name;           /* PRIMARY KEY name, if any */
134 } TableInfo;
135
136 typedef struct _inhInfo
137 {
138         char       *inhrelid;
139         char       *inhparent;
140 } InhInfo;
141
142 typedef struct _indInfo
143 {
144         char       *indexreloid;        /* oid of the index itself */
145         char       *indreloid;          /* oid of the table the index is on */
146         char       *indexrelname;       /* name of the index itself */
147         char       *indrelname;         /* name of the indexed table */
148         char       *indexdef;           /* index definitional command */
149         char       *indisprimary;       /* is this a PK index? */
150         char       *indkey[INDEX_MAX_KEYS]; /* attribute numbers of the key
151                                                                                  * attributes */
152 } IndInfo;
153
154 typedef struct _aggInfo
155 {
156         char       *oid;
157         char       *aggname;
158         char       *aggtransfn;
159         char       *aggfinalfn;
160         char       *aggtranstype;
161         char       *aggbasetype;
162         char       *agginitval;
163         char       *usename;
164         int                     convertok;              /* Flag to indicate of version convertsion
165                                                                  * is OK */
166 } AggInfo;
167
168 typedef struct _oprInfo
169 {
170         char       *oid;
171         char       *oprname;
172         char       *oprkind;            /*----------
173                                                                  *      b = binary,
174                                                                  *      l = left unary
175                                                                  *      r = right unary
176                                                                  *----------
177                                                                  */
178         char       *oprcode;            /* operator function name */
179         char       *oprleft;            /* left operand type */
180         char       *oprright;           /* right operand type */
181         char       *oprcom;                     /* oid of the commutator operator */
182         char       *oprnegate;          /* oid of the negator operator */
183         char       *oprrest;            /* name of the function to calculate
184                                                                  * operator restriction selectivity */
185         char       *oprjoin;            /* name of the function to calculate
186                                                                  * operator join selectivity */
187         char       *oprcanhash;         /* can we use hash join strategy ? */
188         char       *oprlsortop;         /* oid's of the left and right sort
189                                                                  * operators */
190         char       *oprrsortop;
191         char       *usename;
192 } OprInfo;
193
194 /* global decls */
195 extern bool force_quotes;               /* double-quotes for identifiers flag */
196 extern bool g_verbose;                  /* verbose flag */
197 extern Oid      g_last_builtin_oid; /* value of the last builtin oid */
198 extern Archive *g_fout;                 /* the script file */
199
200 /* placeholders for comment starting and ending delimiters */
201 extern char g_comment_start[10];
202 extern char g_comment_end[10];
203
204 extern char g_opaque_type[10];  /* name for the opaque type */
205
206 /* pg_dump is really two programs in one
207         one version works with postgres v4r2
208         and the other works with postgreSQL
209         the common routines are declared here
210 */
211 /*
212  *      common utility functions
213 */
214
215 extern TableInfo *dumpSchema(Archive *fout,
216                    int *numTablesPtr,
217                    const char *tablename,
218                    const bool acls,
219                    const bool oids,
220                    const bool schemaOnly,
221                    const bool dataOnly);
222 extern void dumpSchemaIdx(Archive *fout,
223                           const char *tablename,
224                           TableInfo *tblinfo,
225                           int numTables);
226
227 typedef enum _OidOptions
228 {
229         zeroAsOpaque = 1,
230         zeroAsAny = 2,
231         zeroAsStar = 4,
232         zeroAsNone = 8,
233         useBaseTypeName = 1024
234 } OidOptions;
235
236 extern char *findTypeByOid(TypeInfo *tinfo, int numTypes, const char *oid, OidOptions opts);
237 extern char *findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid);
238 extern int      findFuncByName(FuncInfo *finfo, int numFuncs, const char *name);
239 extern int      findTableByName(TableInfo *tbinfo, int numTables, const char *relname);
240
241 extern void check_conn_and_db(void);
242 extern void parseNumericArray(const char *str, char **array, int arraysize);
243
244 /*
245  * version specific routines
246  */
247 extern TypeInfo *getTypes(int *numTypes);
248 extern FuncInfo *getFuncs(int *numFuncs);
249 extern AggInfo *getAggregates(int *numAggregates);
250
251 extern void clearAggInfo(AggInfo *, int);
252 extern void clearFuncInfo(FuncInfo *, int);
253 extern void clearInhInfo(InhInfo *, int);
254 extern void clearIndInfo(IndInfo *, int);
255 extern void clearOprInfo(OprInfo *, int);
256 extern void clearTypeInfo(TypeInfo *, int);
257
258 extern OprInfo *getOperators(int *numOperators);
259 extern TableInfo *getTables(int *numTables, FuncInfo *finfo, int numFuncs,
260                                                         const char* tablename);
261 extern InhInfo *getInherits(int *numInherits);
262 extern void getTableAttrs(TableInfo *tbinfo, int numTables);
263 extern IndInfo *getIndexes(int *numIndexes);
264 extern void dumpDBComment(Archive *outfile);
265 extern void dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
266                   TypeInfo *tinfo, int numTypes);
267 extern void dumpProcLangs(Archive *fout, FuncInfo *finfo, int numFuncs,
268                           TypeInfo *tinfo, int numTypes);
269 extern void dumpFuncs(Archive *fout, FuncInfo *finfo, int numFuncs,
270                   TypeInfo *tinfo, int numTypes);
271 extern void dumpAggs(Archive *fout, AggInfo *agginfo, int numAggregates,
272                  TypeInfo *tinfo, int numTypes);
273 extern void dumpOprs(Archive *fout, OprInfo *agginfo, int numOperators,
274                  TypeInfo *tinfo, int numTypes);
275 extern void dumpTables(Archive *fout, TableInfo *tbinfo, int numTables,
276                    IndInfo *indinfo, int numIndexes,
277                    InhInfo *inhinfo, int numInherits,
278                    TypeInfo *tinfo, int numTypes, const char *tablename,
279                    const bool acls, const bool oids,
280                    const bool schemaOnly, const bool dataOnly);
281 extern void dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
282                         TableInfo *tbinfo, int numTables, const char *tablename);
283 extern void exit_nicely(void);
284
285 #endif   /* PG_DUMP_H */