~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/pl/plpgsql/src/plpgsql.h

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
 * plpgsql.h            - Definitions for the PL/pgSQL
 
3
 *                        procedural language
 
4
 *
 
5
 * IDENTIFICATION
 
6
 *        $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.56 2004-09-16 16:58:44 tgl Exp $
 
7
 *
 
8
 *        This software is copyrighted by Jan Wieck - Hamburg.
 
9
 *
 
10
 *        The author hereby grants permission  to  use,  copy,  modify,
 
11
 *        distribute,  and      license this software and its documentation
 
12
 *        for any purpose, provided that existing copyright notices are
 
13
 *        retained      in      all  copies  and  that  this notice is included
 
14
 *        verbatim in any distributions. No written agreement, license,
 
15
 *        or  royalty  fee      is required for any of the authorized uses.
 
16
 *        Modifications to this software may be  copyrighted  by  their
 
17
 *        author  and  need  not  follow  the licensing terms described
 
18
 *        here, provided that the new terms are  clearly  indicated  on
 
19
 *        the first page of each file where they apply.
 
20
 *
 
21
 *        IN NO EVENT SHALL THE AUTHOR OR DISTRIBUTORS BE LIABLE TO ANY
 
22
 *        PARTY  FOR  DIRECT,   INDIRECT,       SPECIAL,   INCIDENTAL,   OR
 
23
 *        CONSEQUENTIAL   DAMAGES  ARISING      OUT  OF  THE  USE  OF  THIS
 
24
 *        SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN
 
25
 *        IF  THE  AUTHOR  HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
 
26
 *        DAMAGE.
 
27
 *
 
28
 *        THE  AUTHOR  AND      DISTRIBUTORS  SPECIFICALLY       DISCLAIM       ANY
 
29
 *        WARRANTIES,  INCLUDING,  BUT  NOT  LIMITED  TO,  THE  IMPLIED
 
30
 *        WARRANTIES  OF  MERCHANTABILITY,      FITNESS  FOR  A  PARTICULAR
 
31
 *        PURPOSE,      AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON
 
32
 *        AN "AS IS" BASIS, AND THE AUTHOR      AND  DISTRIBUTORS  HAVE  NO
 
33
 *        OBLIGATION   TO       PROVIDE   MAINTENANCE,   SUPPORT,  UPDATES,
 
34
 *        ENHANCEMENTS, OR MODIFICATIONS.
 
35
 *
 
36
 **********************************************************************/
 
37
#ifndef PLPGSQL_H
 
38
#define PLPGSQL_H
 
39
 
 
40
#include "postgres.h"
 
41
 
 
42
#include "fmgr.h"
 
43
#include "miscadmin.h"
 
44
#include "executor/spi.h"
 
45
#include "commands/trigger.h"
 
46
#include "utils/tuplestore.h"
 
47
 
 
48
/**********************************************************************
 
49
 * Definitions
 
50
 **********************************************************************/
 
51
 
 
52
/* ----------
 
53
 * Compilers namestack item types
 
54
 * ----------
 
55
 */
 
56
enum
 
57
{
 
58
        PLPGSQL_NSTYPE_LABEL,
 
59
        PLPGSQL_NSTYPE_VAR,
 
60
        PLPGSQL_NSTYPE_ROW,
 
61
        PLPGSQL_NSTYPE_REC
 
62
};
 
63
 
 
64
/* ----------
 
65
 * Datum array node types
 
66
 * ----------
 
67
 */
 
68
enum
 
69
{
 
70
        PLPGSQL_DTYPE_VAR,
 
71
        PLPGSQL_DTYPE_ROW,
 
72
        PLPGSQL_DTYPE_REC,
 
73
        PLPGSQL_DTYPE_RECFIELD,
 
74
        PLPGSQL_DTYPE_ARRAYELEM,
 
75
        PLPGSQL_DTYPE_EXPR,
 
76
        PLPGSQL_DTYPE_TRIGARG
 
77
};
 
78
 
 
79
/* ----------
 
80
 * Variants distinguished in PLpgSQL_type structs
 
81
 * ----------
 
82
 */
 
83
enum
 
84
{
 
85
        PLPGSQL_TTYPE_SCALAR,           /* scalar types and domains */
 
86
        PLPGSQL_TTYPE_ROW,                      /* composite types */
 
87
        PLPGSQL_TTYPE_REC,                      /* RECORD pseudotype */
 
88
        PLPGSQL_TTYPE_PSEUDO            /* other pseudotypes */
 
89
};
 
90
 
 
91
/* ----------
 
92
 * Execution tree node types
 
93
 * ----------
 
94
 */
 
95
enum
 
96
{
 
97
        PLPGSQL_STMT_BLOCK,
 
98
        PLPGSQL_STMT_ASSIGN,
 
99
        PLPGSQL_STMT_IF,
 
100
        PLPGSQL_STMT_LOOP,
 
101
        PLPGSQL_STMT_WHILE,
 
102
        PLPGSQL_STMT_FORI,
 
103
        PLPGSQL_STMT_FORS,
 
104
        PLPGSQL_STMT_SELECT,
 
105
        PLPGSQL_STMT_EXIT,
 
106
        PLPGSQL_STMT_RETURN,
 
107
        PLPGSQL_STMT_RETURN_NEXT,
 
108
        PLPGSQL_STMT_RAISE,
 
109
        PLPGSQL_STMT_EXECSQL,
 
110
        PLPGSQL_STMT_DYNEXECUTE,
 
111
        PLPGSQL_STMT_DYNFORS,
 
112
        PLPGSQL_STMT_GETDIAG,
 
113
        PLPGSQL_STMT_OPEN,
 
114
        PLPGSQL_STMT_FETCH,
 
115
        PLPGSQL_STMT_CLOSE,
 
116
        PLPGSQL_STMT_PERFORM
 
117
};
 
118
 
 
119
 
 
120
/* ----------
 
121
 * Execution node return codes
 
122
 * ----------
 
123
 */
 
124
enum
 
125
{
 
126
        PLPGSQL_RC_OK,
 
127
        PLPGSQL_RC_EXIT,
 
128
        PLPGSQL_RC_RETURN
 
129
};
 
130
 
 
131
/* ----------
 
132
 * GET DIAGNOSTICS system attrs
 
133
 * ----------
 
134
 */
 
135
enum
 
136
{
 
137
        PLPGSQL_GETDIAG_ROW_COUNT,
 
138
        PLPGSQL_GETDIAG_RESULT_OID
 
139
};
 
140
 
 
141
 
 
142
/**********************************************************************
 
143
 * Node and structure definitions
 
144
 **********************************************************************/
 
145
 
 
146
 
 
147
typedef struct
 
148
{                                                               /* Dynamic string control structure */
 
149
        int                     alloc;
 
150
        int                     used;
 
151
        char       *value;
 
152
} PLpgSQL_dstring;
 
153
 
 
154
 
 
155
typedef struct
 
156
{                                                               /* Postgres data type */
 
157
        char       *typname;            /* (simple) name of the type */
 
158
        Oid                     typoid;                 /* OID of the data type */
 
159
        int                     ttype;                  /* PLPGSQL_TTYPE_ code */
 
160
        int16           typlen;                 /* stuff copied from its pg_type entry */
 
161
        bool            typbyval;
 
162
        Oid                     typrelid;
 
163
        Oid                     typioparam;
 
164
        FmgrInfo        typinput;               /* lookup info for typinput function */
 
165
        int32           atttypmod;              /* typmod (taken from someplace else) */
 
166
} PLpgSQL_type;
 
167
 
 
168
 
 
169
/*
 
170
 * PLpgSQL_datum is the common supertype for PLpgSQL_expr, PLpgSQL_var,
 
171
 * PLpgSQL_row, PLpgSQL_rec, PLpgSQL_recfield, PLpgSQL_arrayelem, and
 
172
 * PLpgSQL_trigarg
 
173
 */
 
174
typedef struct
 
175
{                                                               /* Generic datum array item             */
 
176
        int                     dtype;
 
177
        int                     dno;
 
178
} PLpgSQL_datum;
 
179
 
 
180
/*
 
181
 * The variants PLpgSQL_var, PLpgSQL_row, and PLpgSQL_rec share these
 
182
 * fields
 
183
 */
 
184
typedef struct
 
185
{                                                               /* Scalar or composite variable */
 
186
        int                     dtype;
 
187
        int                     dno;
 
188
        char       *refname;
 
189
        int                     lineno;
 
190
} PLpgSQL_variable;
 
191
 
 
192
typedef struct PLpgSQL_expr
 
193
{                                                               /* SQL Query to plan and execute        */
 
194
        int                     dtype;
 
195
        int                     exprno;
 
196
        char       *query;
 
197
        void       *plan;
 
198
        Oid                *plan_argtypes;
 
199
        /* fields for "simple expression" fast-path execution: */
 
200
        Expr       *expr_simple_expr;           /* NULL means not a simple expr */
 
201
        Oid                     expr_simple_type;
 
202
        /* if expr is simple AND in use in current xact, these fields are set: */
 
203
        ExprState  *expr_simple_state;
 
204
        struct PLpgSQL_expr *expr_simple_next;
 
205
        /* params to pass to expr */
 
206
        int                     nparams;
 
207
        int                     params[1];              /* VARIABLE SIZE ARRAY ... must be last */
 
208
} PLpgSQL_expr;
 
209
 
 
210
 
 
211
typedef struct
 
212
{                                                               /* Scalar variable */
 
213
        int                     dtype;
 
214
        int                     varno;
 
215
        char       *refname;
 
216
        int                     lineno;
 
217
 
 
218
        PLpgSQL_type *datatype;
 
219
        int                     isconst;
 
220
        int                     notnull;
 
221
        PLpgSQL_expr *default_val;
 
222
        PLpgSQL_expr *cursor_explicit_expr;
 
223
        int                     cursor_explicit_argrow;
 
224
 
 
225
        Datum           value;
 
226
        bool            isnull;
 
227
        bool            freeval;
 
228
} PLpgSQL_var;
 
229
 
 
230
 
 
231
typedef struct
 
232
{                                                               /* Row variable */
 
233
        int                     dtype;
 
234
        int                     rowno;
 
235
        char       *refname;
 
236
        int                     lineno;
 
237
 
 
238
        TupleDesc       rowtupdesc;
 
239
 
 
240
        /*
 
241
         * Note: TupleDesc is only set up for named rowtypes, else it is NULL.
 
242
         *
 
243
         * Note: if the underlying rowtype contains a dropped column, the
 
244
         * corresponding fieldnames[] entry will be NULL, and there is no
 
245
         * corresponding var (varnos[] will be -1).
 
246
         */
 
247
        int                     nfields;
 
248
        char      **fieldnames;
 
249
        int                *varnos;
 
250
} PLpgSQL_row;
 
251
 
 
252
 
 
253
typedef struct
 
254
{                                                               /* Record variable (non-fixed structure) */
 
255
        int                     dtype;
 
256
        int                     recno;
 
257
        char       *refname;
 
258
        int                     lineno;
 
259
 
 
260
        HeapTuple       tup;
 
261
        TupleDesc       tupdesc;
 
262
        bool            freetup;
 
263
        bool            freetupdesc;
 
264
} PLpgSQL_rec;
 
265
 
 
266
 
 
267
typedef struct
 
268
{                                                               /* Field in record */
 
269
        int                     dtype;
 
270
        int                     rfno;
 
271
        char       *fieldname;
 
272
        int                     recparentno;    /* dno of parent record */
 
273
} PLpgSQL_recfield;
 
274
 
 
275
 
 
276
typedef struct
 
277
{                                                               /* Element of array variable */
 
278
        int                     dtype;
 
279
        int                     dno;
 
280
        PLpgSQL_expr *subscript;
 
281
        int                     arrayparentno;  /* dno of parent array variable */
 
282
} PLpgSQL_arrayelem;
 
283
 
 
284
 
 
285
typedef struct
 
286
{                                                               /* Positional argument to trigger       */
 
287
        int                     dtype;
 
288
        int                     dno;
 
289
        PLpgSQL_expr *argnum;
 
290
} PLpgSQL_trigarg;
 
291
 
 
292
 
 
293
typedef struct
 
294
{                                                               /* Item in the compilers namestack      */
 
295
        int                     itemtype;
 
296
        int                     itemno;
 
297
        char            name[1];
 
298
} PLpgSQL_nsitem;
 
299
 
 
300
 
 
301
typedef struct PLpgSQL_ns
 
302
{                                                               /* Compiler namestack level             */
 
303
        int                     items_alloc;
 
304
        int                     items_used;
 
305
        PLpgSQL_nsitem **items;
 
306
        struct PLpgSQL_ns *upper;
 
307
} PLpgSQL_ns;
 
308
 
 
309
 
 
310
typedef struct
 
311
{                                                               /* Generic execution node               */
 
312
        int                     cmd_type;
 
313
        int                     lineno;
 
314
} PLpgSQL_stmt;
 
315
 
 
316
 
 
317
typedef struct
 
318
{                                                               /* List of execution nodes              */
 
319
        int                     stmts_alloc;    /* XXX this oughta just be a List ... */
 
320
        int                     stmts_used;
 
321
        PLpgSQL_stmt **stmts;
 
322
} PLpgSQL_stmts;
 
323
 
 
324
 
 
325
typedef struct PLpgSQL_condition
 
326
{                                                               /* One EXCEPTION condition name */
 
327
        int                     sqlerrstate;    /* SQLSTATE code */
 
328
        char       *condname;           /* condition name (for debugging) */
 
329
        struct PLpgSQL_condition *next;
 
330
} PLpgSQL_condition;
 
331
 
 
332
typedef struct
 
333
{                                                               /* One EXCEPTION ... WHEN clause */
 
334
        int                     lineno;
 
335
        PLpgSQL_condition *conditions;
 
336
        PLpgSQL_stmts *action;
 
337
} PLpgSQL_exception;
 
338
 
 
339
 
 
340
typedef struct
 
341
{                                                               /* List of WHEN clauses                 */
 
342
        int                     exceptions_alloc;               /* XXX this oughta just be a List
 
343
                                                                                 * ... */
 
344
        int                     exceptions_used;
 
345
        PLpgSQL_exception **exceptions;
 
346
} PLpgSQL_exceptions;
 
347
 
 
348
 
 
349
typedef struct
 
350
{                                                               /* Block of statements                  */
 
351
        int                     cmd_type;
 
352
        int                     lineno;
 
353
        char       *label;
 
354
        PLpgSQL_stmts *body;
 
355
        PLpgSQL_exceptions *exceptions;
 
356
        int                     n_initvars;
 
357
        int                *initvarnos;
 
358
} PLpgSQL_stmt_block;
 
359
 
 
360
 
 
361
typedef struct
 
362
{                                                               /* Assign statement                     */
 
363
        int                     cmd_type;
 
364
        int                     lineno;
 
365
        int                     varno;
 
366
        PLpgSQL_expr *expr;
 
367
} PLpgSQL_stmt_assign;
 
368
 
 
369
typedef struct
 
370
{                                                               /* PERFORM statement            */
 
371
        int                     cmd_type;
 
372
        int                     lineno;
 
373
        PLpgSQL_expr *expr;
 
374
} PLpgSQL_stmt_perform;
 
375
 
 
376
typedef struct
 
377
{                                                               /* Get Diagnostics item         */
 
378
        int                     item;                   /* id for diagnostic value desired */
 
379
        int                     target;                 /* where to assign it */
 
380
} PLpgSQL_diag_item;
 
381
 
 
382
typedef struct
 
383
{                                                               /* Get Diagnostics statement            */
 
384
        int                     cmd_type;
 
385
        int                     lineno;
 
386
        int                     ndtitems;
 
387
        PLpgSQL_diag_item *dtitems;
 
388
} PLpgSQL_stmt_getdiag;
 
389
 
 
390
 
 
391
typedef struct
 
392
{                                                               /* IF statement                         */
 
393
        int                     cmd_type;
 
394
        int                     lineno;
 
395
        PLpgSQL_expr *cond;
 
396
        PLpgSQL_stmts *true_body;
 
397
        PLpgSQL_stmts *false_body;
 
398
} PLpgSQL_stmt_if;
 
399
 
 
400
 
 
401
typedef struct
 
402
{                                                               /* Unconditional LOOP statement         */
 
403
        int                     cmd_type;
 
404
        int                     lineno;
 
405
        char       *label;
 
406
        PLpgSQL_stmts *body;
 
407
} PLpgSQL_stmt_loop;
 
408
 
 
409
 
 
410
typedef struct
 
411
{                                                               /* WHILE cond LOOP statement            */
 
412
        int                     cmd_type;
 
413
        int                     lineno;
 
414
        char       *label;
 
415
        PLpgSQL_expr *cond;
 
416
        PLpgSQL_stmts *body;
 
417
} PLpgSQL_stmt_while;
 
418
 
 
419
 
 
420
typedef struct
 
421
{                                                               /* FOR statement with integer loopvar   */
 
422
        int                     cmd_type;
 
423
        int                     lineno;
 
424
        char       *label;
 
425
        PLpgSQL_var *var;
 
426
        PLpgSQL_expr *lower;
 
427
        PLpgSQL_expr *upper;
 
428
        int                     reverse;
 
429
        PLpgSQL_stmts *body;
 
430
} PLpgSQL_stmt_fori;
 
431
 
 
432
 
 
433
typedef struct
 
434
{                                                               /* FOR statement running over SELECT    */
 
435
        int                     cmd_type;
 
436
        int                     lineno;
 
437
        char       *label;
 
438
        PLpgSQL_rec *rec;
 
439
        PLpgSQL_row *row;
 
440
        PLpgSQL_expr *query;
 
441
        PLpgSQL_stmts *body;
 
442
} PLpgSQL_stmt_fors;
 
443
 
 
444
 
 
445
typedef struct
 
446
{                                                               /* FOR statement running over EXECUTE   */
 
447
        int                     cmd_type;
 
448
        int                     lineno;
 
449
        char       *label;
 
450
        PLpgSQL_rec *rec;
 
451
        PLpgSQL_row *row;
 
452
        PLpgSQL_expr *query;
 
453
        PLpgSQL_stmts *body;
 
454
} PLpgSQL_stmt_dynfors;
 
455
 
 
456
 
 
457
typedef struct
 
458
{                                                               /* SELECT ... INTO statement            */
 
459
        int                     cmd_type;
 
460
        int                     lineno;
 
461
        PLpgSQL_rec *rec;
 
462
        PLpgSQL_row *row;
 
463
        PLpgSQL_expr *query;
 
464
} PLpgSQL_stmt_select;
 
465
 
 
466
 
 
467
typedef struct
 
468
{                                                               /* OPEN a curvar                                        */
 
469
        int                     cmd_type;
 
470
        int                     lineno;
 
471
        int                     curvar;
 
472
        PLpgSQL_row *returntype;
 
473
        PLpgSQL_expr *argquery;
 
474
        PLpgSQL_expr *query;
 
475
        PLpgSQL_expr *dynquery;
 
476
} PLpgSQL_stmt_open;
 
477
 
 
478
 
 
479
typedef struct
 
480
{                                                               /* FETCH curvar INTO statement          */
 
481
        int                     cmd_type;
 
482
        int                     lineno;
 
483
        PLpgSQL_rec *rec;
 
484
        PLpgSQL_row *row;
 
485
        int                     curvar;
 
486
} PLpgSQL_stmt_fetch;
 
487
 
 
488
 
 
489
typedef struct
 
490
{                                                               /* CLOSE curvar                                         */
 
491
        int                     cmd_type;
 
492
        int                     lineno;
 
493
        int                     curvar;
 
494
} PLpgSQL_stmt_close;
 
495
 
 
496
 
 
497
typedef struct
 
498
{                                                               /* EXIT statement                       */
 
499
        int                     cmd_type;
 
500
        int                     lineno;
 
501
        char       *label;
 
502
        PLpgSQL_expr *cond;
 
503
} PLpgSQL_stmt_exit;
 
504
 
 
505
 
 
506
typedef struct
 
507
{                                                               /* RETURN statement                     */
 
508
        int                     cmd_type;
 
509
        int                     lineno;
 
510
        PLpgSQL_expr *expr;
 
511
        int                     retrecno;
 
512
        int                     retrowno;
 
513
} PLpgSQL_stmt_return;
 
514
 
 
515
typedef struct
 
516
{                                                               /* RETURN NEXT statement */
 
517
        int                     cmd_type;
 
518
        int                     lineno;
 
519
        PLpgSQL_rec *rec;
 
520
        PLpgSQL_row *row;
 
521
        PLpgSQL_expr *expr;
 
522
} PLpgSQL_stmt_return_next;
 
523
 
 
524
typedef struct
 
525
{                                                               /* RAISE statement                      */
 
526
        int                     cmd_type;
 
527
        int                     lineno;
 
528
        int                     elog_level;
 
529
        char       *message;
 
530
        int                     nparams;
 
531
        int                *params;
 
532
} PLpgSQL_stmt_raise;
 
533
 
 
534
 
 
535
typedef struct
 
536
{                                                               /* Generic SQL statement to execute */
 
537
        int                     cmd_type;
 
538
        int                     lineno;
 
539
        PLpgSQL_expr *sqlstmt;
 
540
} PLpgSQL_stmt_execsql;
 
541
 
 
542
 
 
543
typedef struct
 
544
{                                                               /* Dynamic SQL string to execute */
 
545
        int                     cmd_type;
 
546
        int                     lineno;
 
547
        PLpgSQL_expr *query;
 
548
} PLpgSQL_stmt_dynexecute;
 
549
 
 
550
 
 
551
typedef struct PLpgSQL_func_hashkey
 
552
{                                                               /* Hash lookup key for functions */
 
553
        Oid                     funcOid;
 
554
 
 
555
        /*
 
556
         * For a trigger function, the OID of the relation triggered on is
 
557
         * part of the hashkey --- we want to compile the trigger separately
 
558
         * for each relation it is used with, in case the rowtype is
 
559
         * different.  Zero if not called as a trigger.
 
560
         */
 
561
        Oid                     trigrelOid;
 
562
 
 
563
        /*
 
564
         * We include actual argument types in the hash key to support
 
565
         * polymorphic PLpgSQL functions.  Be careful that extra positions are
 
566
         * zeroed!
 
567
         */
 
568
        Oid                     argtypes[FUNC_MAX_ARGS];
 
569
} PLpgSQL_func_hashkey;
 
570
 
 
571
 
 
572
typedef struct PLpgSQL_function
 
573
{                                                               /* Complete compiled function     */
 
574
        char       *fn_name;
 
575
        Oid                     fn_oid;
 
576
        TransactionId fn_xmin;
 
577
        CommandId       fn_cmin;
 
578
        int                     fn_functype;
 
579
        PLpgSQL_func_hashkey *fn_hashkey;       /* back-link to hashtable key */
 
580
 
 
581
        Oid                     fn_rettype;
 
582
        int                     fn_rettyplen;
 
583
        bool            fn_retbyval;
 
584
        FmgrInfo        fn_retinput;
 
585
        Oid                     fn_rettypioparam;
 
586
        bool            fn_retistuple;
 
587
        bool            fn_retset;
 
588
        bool            fn_readonly;
 
589
 
 
590
        int                     fn_nargs;
 
591
        int                     fn_argvarnos[FUNC_MAX_ARGS];
 
592
        int                     found_varno;
 
593
        int                     new_varno;
 
594
        int                     old_varno;
 
595
        int                     tg_name_varno;
 
596
        int                     tg_when_varno;
 
597
        int                     tg_level_varno;
 
598
        int                     tg_op_varno;
 
599
        int                     tg_relid_varno;
 
600
        int                     tg_relname_varno;
 
601
        int                     tg_nargs_varno;
 
602
 
 
603
        int                     ndatums;
 
604
        PLpgSQL_datum **datums;
 
605
        PLpgSQL_stmt_block *action;
 
606
} PLpgSQL_function;
 
607
 
 
608
 
 
609
typedef struct
 
610
{                                                               /* Runtime execution data       */
 
611
        Datum           retval;
 
612
        bool            retisnull;
 
613
        Oid                     rettype;                /* type of current retval */
 
614
 
 
615
        Oid                     fn_rettype;             /* info about declared function rettype */
 
616
        bool            retistuple;
 
617
        bool            retisset;
 
618
 
 
619
        bool            readonly_func;
 
620
 
 
621
        TupleDesc       rettupdesc;
 
622
        char       *exitlabel;
 
623
 
 
624
        Tuplestorestate *tuple_store;           /* SRFs accumulate results here */
 
625
        MemoryContext tuple_store_cxt;
 
626
        ReturnSetInfo *rsi;
 
627
 
 
628
        int                     trig_nargs;
 
629
        Datum      *trig_argv;
 
630
 
 
631
        int                     found_varno;
 
632
        int                     ndatums;
 
633
        PLpgSQL_datum **datums;
 
634
 
 
635
        /* temporary state for results from evaluation of query or expr */
 
636
        SPITupleTable *eval_tuptable;
 
637
        uint32          eval_processed;
 
638
        Oid                     eval_lastoid;
 
639
        ExprContext *eval_econtext;
 
640
 
 
641
        /* status information for error context reporting */
 
642
        PLpgSQL_function *err_func; /* current func */
 
643
        PLpgSQL_stmt *err_stmt;         /* current stmt */
 
644
        const char *err_text;           /* additional state info */
 
645
} PLpgSQL_execstate;
 
646
 
 
647
 
 
648
/**********************************************************************
 
649
 * Global variable declarations
 
650
 **********************************************************************/
 
651
 
 
652
extern int      plpgsql_DumpExecTree;
 
653
extern int      plpgsql_SpaceScanned;
 
654
extern int      plpgsql_nDatums;
 
655
extern PLpgSQL_datum **plpgsql_Datums;
 
656
 
 
657
extern int      plpgsql_error_lineno;
 
658
extern char *plpgsql_error_funcname;
 
659
 
 
660
/* linkage to the real yytext variable */
 
661
extern char *plpgsql_base_yytext;
 
662
 
 
663
#define plpgsql_yytext plpgsql_base_yytext
 
664
 
 
665
extern PLpgSQL_function *plpgsql_curr_compile;
 
666
 
 
667
/**********************************************************************
 
668
 * Function declarations
 
669
 **********************************************************************/
 
670
 
 
671
/* ----------
 
672
 * Functions in pl_comp.c
 
673
 * ----------
 
674
 */
 
675
extern PLpgSQL_function *plpgsql_compile(FunctionCallInfo fcinfo,
 
676
                                bool forValidator);
 
677
extern int      plpgsql_parse_word(char *word);
 
678
extern int      plpgsql_parse_dblword(char *word);
 
679
extern int      plpgsql_parse_tripword(char *word);
 
680
extern int      plpgsql_parse_wordtype(char *word);
 
681
extern int      plpgsql_parse_dblwordtype(char *word);
 
682
extern int      plpgsql_parse_tripwordtype(char *word);
 
683
extern int      plpgsql_parse_wordrowtype(char *word);
 
684
extern int      plpgsql_parse_dblwordrowtype(char *word);
 
685
extern PLpgSQL_type *plpgsql_parse_datatype(const char *string);
 
686
extern PLpgSQL_type *plpgsql_build_datatype(Oid typeOid, int32 typmod);
 
687
extern PLpgSQL_variable *plpgsql_build_variable(char *refname, int lineno,
 
688
                                           PLpgSQL_type *dtype,
 
689
                                           bool add2namespace);
 
690
extern PLpgSQL_condition *plpgsql_parse_err_condition(char *condname);
 
691
extern void plpgsql_adddatum(PLpgSQL_datum *new);
 
692
extern int      plpgsql_add_initdatums(int **varnos);
 
693
extern void plpgsql_HashTableInit(void);
 
694
 
 
695
/* ----------
 
696
 * Functions in pl_handler.c
 
697
 * ----------
 
698
 */
 
699
extern void plpgsql_init(void);
 
700
extern Datum plpgsql_call_handler(PG_FUNCTION_ARGS);
 
701
extern Datum plpgsql_validator(PG_FUNCTION_ARGS);
 
702
 
 
703
/* ----------
 
704
 * Functions in pl_exec.c
 
705
 * ----------
 
706
 */
 
707
extern Datum plpgsql_exec_function(PLpgSQL_function *func,
 
708
                                          FunctionCallInfo fcinfo);
 
709
extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function *func,
 
710
                                         TriggerData *trigdata);
 
711
extern void plpgsql_xact_cb(XactEvent event, void *arg);
 
712
 
 
713
/* ----------
 
714
 * Functions for the dynamic string handling in pl_funcs.c
 
715
 * ----------
 
716
 */
 
717
extern void plpgsql_dstring_init(PLpgSQL_dstring *ds);
 
718
extern void plpgsql_dstring_free(PLpgSQL_dstring *ds);
 
719
extern void plpgsql_dstring_append(PLpgSQL_dstring *ds, const char *str);
 
720
extern char *plpgsql_dstring_get(PLpgSQL_dstring *ds);
 
721
 
 
722
/* ----------
 
723
 * Functions for the namestack handling in pl_funcs.c
 
724
 * ----------
 
725
 */
 
726
extern void plpgsql_ns_init(void);
 
727
extern bool plpgsql_ns_setlocal(bool flag);
 
728
extern void plpgsql_ns_push(char *label);
 
729
extern void plpgsql_ns_pop(void);
 
730
extern void plpgsql_ns_additem(int itemtype, int itemno, char *name);
 
731
extern PLpgSQL_nsitem *plpgsql_ns_lookup(char *name, char *nsname);
 
732
extern void plpgsql_ns_rename(char *oldname, char *newname);
 
733
 
 
734
/* ----------
 
735
 * Other functions in pl_funcs.c
 
736
 * ----------
 
737
 */
 
738
extern void plpgsql_convert_ident(const char *s, char **output, int numidents);
 
739
extern const char *plpgsql_stmt_typename(PLpgSQL_stmt *stmt);
 
740
extern void plpgsql_dumptree(PLpgSQL_function *func);
 
741
 
 
742
/* ----------
 
743
 * Externs in gram.y and scan.l
 
744
 * ----------
 
745
 */
 
746
extern PLpgSQL_expr *plpgsql_read_expression(int until, const char *expected);
 
747
extern int      plpgsql_yyparse(void);
 
748
extern int      plpgsql_base_yylex(void);
 
749
extern int      plpgsql_yylex(void);
 
750
extern void plpgsql_push_back_token(int token);
 
751
extern void plpgsql_yyerror(const char *message);
 
752
extern int      plpgsql_scanner_lineno(void);
 
753
extern void plpgsql_scanner_init(const char *str, int functype);
 
754
extern void plpgsql_scanner_finish(void);
 
755
extern char *plpgsql_get_string_value(void);
 
756
 
 
757
#endif   /* PLPGSQL_H */