]> git.8kb.co.uk Git - pgpool-ii/pgpool-ii_2.2.5/blob - parser/makefuncs.c
Attempt to send a proper failure message to frontend when authentication
[pgpool-ii/pgpool-ii_2.2.5] / parser / makefuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * makefuncs.c
4  *        creator functions for primitive nodes. The functions here are for
5  *        the most frequently created nodes.
6  *
7  * Portions Copyright (c) 2003-2008, PgPool Global Development Group
8  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  *
12  * IDENTIFICATION
13  *        $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.57 2007/09/06 17:31:58 tgl Exp $
14  *
15  *-------------------------------------------------------------------------
16  */
17 #include "pool_parser.h"
18
19 #include "makefuncs.h"
20 #include "pool_memory.h"
21 #include <stdlib.h>
22 #include <string.h>
23
24 #define ereport(a,b)
25 #define elog(a,b)
26
27 #define BOOLOID 16
28
29
30 /*
31  * makeA_Expr -
32  *              makes an A_Expr node
33  */
34 A_Expr *
35 makeA_Expr(A_Expr_Kind kind, List *name,
36                    Node *lexpr, Node *rexpr, int location)
37 {
38         A_Expr     *a = makeNode(A_Expr);
39
40         a->kind = kind;
41         a->name = name;
42         a->lexpr = lexpr;
43         a->rexpr = rexpr;
44         a->location = location;
45         return a;
46 }
47
48 /*
49  * makeSimpleA_Expr -
50  *              As above, given a simple (unqualified) operator name
51  */
52 A_Expr *
53 makeSimpleA_Expr(A_Expr_Kind kind, const char *name,
54                                  Node *lexpr, Node *rexpr, int location)
55 {
56         A_Expr     *a = makeNode(A_Expr);
57
58         a->kind = kind;
59         a->name = list_make1(makeString((char *) name));
60         a->lexpr = lexpr;
61         a->rexpr = rexpr;
62         a->location = location;
63         return a;
64 }
65
66 /*
67  * makeVar -
68  *        creates a Var node
69  */
70 Var *
71 makeVar(Index varno,
72                 AttrNumber varattno,
73                 Oid vartype,
74                 int32 vartypmod,
75                 Index varlevelsup)
76 {
77         Var                *var = makeNode(Var);
78
79         var->varno = varno;
80         var->varattno = varattno;
81         var->vartype = vartype;
82         var->vartypmod = vartypmod;
83         var->varlevelsup = varlevelsup;
84
85         /*
86          * Since few if any routines ever create Var nodes with varnoold/varoattno
87          * different from varno/varattno, we don't provide separate arguments for
88          * them, but just initialize them to the given varno/varattno. This
89          * reduces code clutter and chance of error for most callers.
90          */
91         var->varnoold = varno;
92         var->varoattno = varattno;
93
94         return var;
95 }
96
97 /*
98  * makeTargetEntry -
99  *        creates a TargetEntry node
100  */
101 TargetEntry *
102 makeTargetEntry(Expr *expr,
103                                 AttrNumber resno,
104                                 char *resname,
105                                 bool resjunk)
106 {
107         TargetEntry *tle = makeNode(TargetEntry);
108
109         tle->expr = expr;
110         tle->resno = resno;
111         tle->resname = resname;
112
113         /*
114          * We always set these fields to 0. If the caller wants to change them he
115          * must do so explicitly.  Few callers do that, so omitting these
116          * arguments reduces the chance of error.
117          */
118         tle->ressortgroupref = 0;
119         tle->resorigtbl = InvalidOid;
120         tle->resorigcol = 0;
121
122         tle->resjunk = resjunk;
123
124         return tle;
125 }
126
127 /*
128  * flatCopyTargetEntry -
129  *        duplicate a TargetEntry, but don't copy substructure
130  *
131  * This is commonly used when we just want to modify the resno or substitute
132  * a new expression.
133  */
134 TargetEntry *
135 flatCopyTargetEntry(TargetEntry *src_tle)
136 {
137         TargetEntry *tle = makeNode(TargetEntry);
138
139         memcpy(tle, src_tle, sizeof(TargetEntry));
140         return tle;
141 }
142
143 /*
144  * makeFromExpr -
145  *        creates a FromExpr node
146  */
147 FromExpr *
148 makeFromExpr(List *fromlist, Node *quals)
149 {
150         FromExpr   *f = makeNode(FromExpr);
151
152         f->fromlist = fromlist;
153         f->quals = quals;
154         return f;
155 }
156
157 /*
158  * makeConst -
159  *        creates a Const node
160  */
161 Const *
162 makeConst(Oid consttype,
163                   int32 consttypmod,
164                   int constlen,
165                   Datum constvalue,
166                   bool constisnull,
167                   bool constbyval)
168 {
169         Const      *cnst = makeNode(Const);
170
171         cnst->consttype = consttype;
172         cnst->consttypmod = consttypmod;
173         cnst->constlen = constlen;
174         cnst->constvalue = constvalue;
175         cnst->constisnull = constisnull;
176         cnst->constbyval = constbyval;
177
178         return cnst;
179 }
180
181 #if 0
182 /*
183  * makeNullConst -
184  *        creates a Const node representing a NULL of the specified type/typmod
185  *
186  * This is a convenience routine that just saves a lookup of the type's
187  * storage properties.
188  */
189 Const *
190 makeNullConst(Oid consttype, int32 consttypmod)
191 {
192         int16           typLen;
193         bool            typByVal;
194
195         get_typlenbyval(consttype, &typLen, &typByVal);
196         return makeConst(consttype,
197                                          consttypmod,
198                                          (int) typLen,
199                                          (Datum) 0,
200                                          true,
201                                          typByVal);
202 }
203 #endif
204
205 #if 0
206 /*
207  * makeBoolConst -
208  *        creates a Const node representing a boolean value (can be NULL too)
209  */
210 Node *
211 makeBoolConst(bool value, bool isnull)
212 {
213         /* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
214         return (Node *) makeConst(BOOLOID, -1, 1,
215                                                           BoolGetDatum(value), isnull, true);
216 }
217 #endif
218
219 /*
220  * makeBoolExpr -
221  *        creates a BoolExpr node
222  */
223 Expr *
224 makeBoolExpr(BoolExprType boolop, List *args)
225 {
226         BoolExpr   *b = makeNode(BoolExpr);
227
228         b->boolop = boolop;
229         b->args = args;
230
231         return (Expr *) b;
232 }
233
234 /*
235  * makeAlias -
236  *        creates an Alias node
237  *
238  * NOTE: the given name is copied, but the colnames list (if any) isn't.
239  */
240 Alias *
241 makeAlias(const char *aliasname, List *colnames)
242 {
243         Alias      *a = makeNode(Alias);
244
245         a->aliasname = pstrdup(aliasname);
246         a->colnames = colnames;
247
248         return a;
249 }
250
251 /*
252  * makeRelabelType -
253  *        creates a RelabelType node
254  */
255 RelabelType *
256 makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, CoercionForm rformat)
257 {
258         RelabelType *r = makeNode(RelabelType);
259
260         r->arg = arg;
261         r->resulttype = rtype;
262         r->resulttypmod = rtypmod;
263         r->relabelformat = rformat;
264
265         return r;
266 }
267
268 /*
269  * makeRangeVar -
270  *        creates a RangeVar node (rather oversimplified case)
271  */
272 RangeVar *
273 makeRangeVar(char *schemaname, char *relname)
274 {
275         RangeVar   *r = makeNode(RangeVar);
276
277         r->catalogname = NULL;
278         r->schemaname = schemaname;
279         r->relname = relname;
280         r->inhOpt = INH_DEFAULT;
281         r->istemp = false;
282         r->alias = NULL;
283
284         return r;
285 }
286
287 /*
288  * makeTypeName -
289  *      build a TypeName node for an unqualified name.
290  *
291  * typmod is defaulted, but can be changed later by caller.
292  */
293 TypeName *
294 makeTypeName(char *typnam)
295 {
296         return makeTypeNameFromNameList(list_make1(makeString(typnam)));
297 }
298
299 /*
300  * makeTypeNameFromNameList -
301  *      build a TypeName node for a String list representing a qualified name.
302  *
303  * typmod is defaulted, but can be changed later by caller.
304  */
305 TypeName *
306 makeTypeNameFromNameList(List *names)
307 {
308         TypeName   *n = makeNode(TypeName);
309
310         n->names = names;
311         n->typmods = NIL;
312         n->typemod = -1;
313         n->location = -1;
314         return n;
315 }
316
317 /*
318  * makeTypeNameFromOid -
319  *      build a TypeName node to represent a type already known by OID/typmod.
320  */
321 TypeName *
322 makeTypeNameFromOid(Oid typeid, int32 typmod)
323 {
324         TypeName   *n = makeNode(TypeName);
325
326         n->typeid = typeid;
327         n->typemod = typmod;
328         n->location = -1;
329         return n;
330 }
331
332 /*
333  * makeFuncExpr -
334  *      build an expression tree representing a function call.
335  *
336  * The argument expressions must have been transformed already.
337  */
338 FuncExpr *
339 makeFuncExpr(Oid funcid, Oid rettype, List *args, CoercionForm fformat)
340 {
341         FuncExpr   *funcexpr;
342
343         funcexpr = makeNode(FuncExpr);
344         funcexpr->funcid = funcid;
345         funcexpr->funcresulttype = rettype;
346         funcexpr->funcretset = false;           /* only allowed case here */
347         funcexpr->funcformat = fformat;
348         funcexpr->args = args;
349
350         return funcexpr;
351 }
352
353 /*
354  * makeDefElem -
355  *      build a DefElem node
356  */
357 DefElem *
358 makeDefElem(char *name, Node *arg)
359 {
360         DefElem    *res = makeNode(DefElem);
361
362         res->defname = name;
363         res->arg = arg;
364         return res;
365 }