]> granicus.if.org Git - postgresql/blob - src/pl/plpgsql/src/plpgsql.h
a50d5721f437dc93b2e9e9cd5eb4fe61dd5b3cc7
[postgresql] / src / pl / plpgsql / src / plpgsql.h
1 /*-------------------------------------------------------------------------
2  *
3  * plpgsql.h            - Definitions for the PL/pgSQL
4  *                        procedural language
5  *
6  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.97 2008/04/06 23:43:29 tgl Exp $
12  *
13  *-------------------------------------------------------------------------
14  */
15
16 #ifndef PLPGSQL_H
17 #define PLPGSQL_H
18
19 #include "postgres.h"
20
21 #include "fmgr.h"
22 #include "miscadmin.h"
23 #include "commands/trigger.h"
24 #include "executor/spi.h"
25 #include "utils/tuplestore.h"
26
27 /**********************************************************************
28  * Definitions
29  **********************************************************************/
30
31 /* ----------
32  * Compiler's namestack item types
33  * ----------
34  */
35 enum
36 {
37         PLPGSQL_NSTYPE_LABEL,
38         PLPGSQL_NSTYPE_VAR,
39         PLPGSQL_NSTYPE_ROW,
40         PLPGSQL_NSTYPE_REC
41 };
42
43 /* ----------
44  * Datum array node types
45  * ----------
46  */
47 enum
48 {
49         PLPGSQL_DTYPE_VAR,
50         PLPGSQL_DTYPE_ROW,
51         PLPGSQL_DTYPE_REC,
52         PLPGSQL_DTYPE_RECFIELD,
53         PLPGSQL_DTYPE_ARRAYELEM,
54         PLPGSQL_DTYPE_EXPR,
55         PLPGSQL_DTYPE_TRIGARG
56 };
57
58 /* ----------
59  * Variants distinguished in PLpgSQL_type structs
60  * ----------
61  */
62 enum
63 {
64         PLPGSQL_TTYPE_SCALAR,           /* scalar types and domains */
65         PLPGSQL_TTYPE_ROW,                      /* composite types */
66         PLPGSQL_TTYPE_REC,                      /* RECORD pseudotype */
67         PLPGSQL_TTYPE_PSEUDO            /* other pseudotypes */
68 };
69
70 /* ----------
71  * Execution tree node types
72  * ----------
73  */
74 enum
75 {
76         PLPGSQL_STMT_BLOCK,
77         PLPGSQL_STMT_ASSIGN,
78         PLPGSQL_STMT_IF,
79         PLPGSQL_STMT_LOOP,
80         PLPGSQL_STMT_WHILE,
81         PLPGSQL_STMT_FORI,
82         PLPGSQL_STMT_FORS,
83         PLPGSQL_STMT_FORC,
84         PLPGSQL_STMT_EXIT,
85         PLPGSQL_STMT_RETURN,
86         PLPGSQL_STMT_RETURN_NEXT,
87         PLPGSQL_STMT_RETURN_QUERY,
88         PLPGSQL_STMT_RAISE,
89         PLPGSQL_STMT_EXECSQL,
90         PLPGSQL_STMT_DYNEXECUTE,
91         PLPGSQL_STMT_DYNFORS,
92         PLPGSQL_STMT_GETDIAG,
93         PLPGSQL_STMT_OPEN,
94         PLPGSQL_STMT_FETCH,
95         PLPGSQL_STMT_CLOSE,
96         PLPGSQL_STMT_PERFORM
97 };
98
99
100 /* ----------
101  * Execution node return codes
102  * ----------
103  */
104 enum
105 {
106         PLPGSQL_RC_OK,
107         PLPGSQL_RC_EXIT,
108         PLPGSQL_RC_RETURN,
109         PLPGSQL_RC_CONTINUE
110 };
111
112 /* ----------
113  * GET DIAGNOSTICS system attrs
114  * ----------
115  */
116 enum
117 {
118         PLPGSQL_GETDIAG_ROW_COUNT,
119         PLPGSQL_GETDIAG_RESULT_OID
120 };
121
122
123 /**********************************************************************
124  * Node and structure definitions
125  **********************************************************************/
126
127
128 typedef struct
129 {                                                               /* Dynamic string control structure */
130         int                     alloc;
131         int                     used;                   /* Including NUL terminator */
132         char       *value;
133 } PLpgSQL_dstring;
134
135
136 typedef struct
137 {                                                               /* Postgres data type */
138         char       *typname;            /* (simple) name of the type */
139         Oid                     typoid;                 /* OID of the data type */
140         int                     ttype;                  /* PLPGSQL_TTYPE_ code */
141         int16           typlen;                 /* stuff copied from its pg_type entry */
142         bool            typbyval;
143         Oid                     typrelid;
144         Oid                     typioparam;
145         FmgrInfo        typinput;               /* lookup info for typinput function */
146         int32           atttypmod;              /* typmod (taken from someplace else) */
147 } PLpgSQL_type;
148
149
150 /*
151  * PLpgSQL_datum is the common supertype for PLpgSQL_expr, PLpgSQL_var,
152  * PLpgSQL_row, PLpgSQL_rec, PLpgSQL_recfield, PLpgSQL_arrayelem, and
153  * PLpgSQL_trigarg
154  */
155 typedef struct
156 {                                                               /* Generic datum array item             */
157         int                     dtype;
158         int                     dno;
159 } PLpgSQL_datum;
160
161 /*
162  * The variants PLpgSQL_var, PLpgSQL_row, and PLpgSQL_rec share these
163  * fields
164  */
165 typedef struct
166 {                                                               /* Scalar or composite variable */
167         int                     dtype;
168         int                     dno;
169         char       *refname;
170         int                     lineno;
171 } PLpgSQL_variable;
172
173 typedef struct PLpgSQL_expr
174 {                                                               /* SQL Query to plan and execute        */
175         int                     dtype;
176         int                     exprno;
177         char       *query;
178         SPIPlanPtr      plan;
179         Oid                *plan_argtypes;
180         /* fields for "simple expression" fast-path execution: */
181         Expr       *expr_simple_expr;           /* NULL means not a simple expr */
182         int                     expr_simple_generation; /* plancache generation we checked */
183         Oid                     expr_simple_type;               /* result type Oid, if simple */
184
185         /*
186          * if expr is simple AND prepared in current eval_estate,
187          * expr_simple_state is valid.  Test validity by seeing if expr_simple_id
188          * matches eval_estate_simple_id.
189          */
190         ExprState  *expr_simple_state;
191         long int        expr_simple_id;
192
193         /* params to pass to expr */
194         int                     nparams;
195         int                     params[1];              /* VARIABLE SIZE ARRAY ... must be last */
196 } PLpgSQL_expr;
197
198
199 typedef struct
200 {                                                               /* Scalar variable */
201         int                     dtype;
202         int                     varno;
203         char       *refname;
204         int                     lineno;
205
206         PLpgSQL_type *datatype;
207         int                     isconst;
208         int                     notnull;
209         PLpgSQL_expr *default_val;
210         PLpgSQL_expr *cursor_explicit_expr;
211         int                     cursor_explicit_argrow;
212         int                     cursor_options;
213
214         Datum           value;
215         bool            isnull;
216         bool            freeval;
217 } PLpgSQL_var;
218
219
220 typedef struct
221 {                                                               /* Row variable */
222         int                     dtype;
223         int                     rowno;
224         char       *refname;
225         int                     lineno;
226
227         TupleDesc       rowtupdesc;
228
229         /*
230          * Note: TupleDesc is only set up for named rowtypes, else it is NULL.
231          *
232          * Note: if the underlying rowtype contains a dropped column, the
233          * corresponding fieldnames[] entry will be NULL, and there is no
234          * corresponding var (varnos[] will be -1).
235          */
236         int                     nfields;
237         char      **fieldnames;
238         int                *varnos;
239 } PLpgSQL_row;
240
241
242 typedef struct
243 {                                                               /* Record variable (non-fixed structure) */
244         int                     dtype;
245         int                     recno;
246         char       *refname;
247         int                     lineno;
248
249         HeapTuple       tup;
250         TupleDesc       tupdesc;
251         bool            freetup;
252         bool            freetupdesc;
253 } PLpgSQL_rec;
254
255
256 typedef struct
257 {                                                               /* Field in record */
258         int                     dtype;
259         int                     rfno;
260         char       *fieldname;
261         int                     recparentno;    /* dno of parent record */
262 } PLpgSQL_recfield;
263
264
265 typedef struct
266 {                                                               /* Element of array variable */
267         int                     dtype;
268         int                     dno;
269         PLpgSQL_expr *subscript;
270         int                     arrayparentno;  /* dno of parent array variable */
271 } PLpgSQL_arrayelem;
272
273
274 typedef struct
275 {                                                               /* Positional argument to trigger       */
276         int                     dtype;
277         int                     dno;
278         PLpgSQL_expr *argnum;
279 } PLpgSQL_trigarg;
280
281
282 typedef struct
283 {                                                               /* Item in the compilers namestack      */
284         int                     itemtype;
285         int                     itemno;
286         char            name[1];
287 } PLpgSQL_nsitem;
288
289
290 /* XXX: consider adapting this to use List */
291 typedef struct PLpgSQL_ns
292 {                                                               /* Compiler namestack level             */
293         int                     items_alloc;
294         int                     items_used;
295         PLpgSQL_nsitem **items;
296         struct PLpgSQL_ns *upper;
297 } PLpgSQL_ns;
298
299
300 typedef struct
301 {                                                               /* Generic execution node               */
302         int                     cmd_type;
303         int                     lineno;
304 } PLpgSQL_stmt;
305
306
307 typedef struct PLpgSQL_condition
308 {                                                               /* One EXCEPTION condition name */
309         int                     sqlerrstate;    /* SQLSTATE code */
310         char       *condname;           /* condition name (for debugging) */
311         struct PLpgSQL_condition *next;
312 } PLpgSQL_condition;
313
314 typedef struct
315 {
316         int                     sqlstate_varno;
317         int                     sqlerrm_varno;
318         List       *exc_list;           /* List of WHEN clauses */
319 } PLpgSQL_exception_block;
320
321 typedef struct
322 {                                                               /* One EXCEPTION ... WHEN clause */
323         int                     lineno;
324         PLpgSQL_condition *conditions;
325         List       *action;                     /* List of statements */
326 } PLpgSQL_exception;
327
328
329 typedef struct
330 {                                                               /* Block of statements                  */
331         int                     cmd_type;
332         int                     lineno;
333         char       *label;
334         List       *body;                       /* List of statements */
335         int                     n_initvars;
336         int                *initvarnos;
337         PLpgSQL_exception_block *exceptions;
338 } PLpgSQL_stmt_block;
339
340
341 typedef struct
342 {                                                               /* Assign statement                     */
343         int                     cmd_type;
344         int                     lineno;
345         int                     varno;
346         PLpgSQL_expr *expr;
347 } PLpgSQL_stmt_assign;
348
349 typedef struct
350 {                                                               /* PERFORM statement            */
351         int                     cmd_type;
352         int                     lineno;
353         PLpgSQL_expr *expr;
354 } PLpgSQL_stmt_perform;
355
356 typedef struct
357 {                                                               /* Get Diagnostics item         */
358         int                     kind;                   /* id for diagnostic value desired */
359         int                     target;                 /* where to assign it */
360 } PLpgSQL_diag_item;
361
362 typedef struct
363 {                                                               /* Get Diagnostics statement            */
364         int                     cmd_type;
365         int                     lineno;
366         List       *diag_items;         /* List of PLpgSQL_diag_item */
367 } PLpgSQL_stmt_getdiag;
368
369
370 typedef struct
371 {                                                               /* IF statement                         */
372         int                     cmd_type;
373         int                     lineno;
374         PLpgSQL_expr *cond;
375         List       *true_body;          /* List of statements */
376         List       *false_body;         /* List of statements */
377 } PLpgSQL_stmt_if;
378
379
380 typedef struct
381 {                                                               /* Unconditional LOOP statement         */
382         int                     cmd_type;
383         int                     lineno;
384         char       *label;
385         List       *body;                       /* List of statements */
386 } PLpgSQL_stmt_loop;
387
388
389 typedef struct
390 {                                                               /* WHILE cond LOOP statement            */
391         int                     cmd_type;
392         int                     lineno;
393         char       *label;
394         PLpgSQL_expr *cond;
395         List       *body;                       /* List of statements */
396 } PLpgSQL_stmt_while;
397
398
399 typedef struct
400 {                                                               /* FOR statement with integer loopvar   */
401         int                     cmd_type;
402         int                     lineno;
403         char       *label;
404         PLpgSQL_var *var;
405         PLpgSQL_expr *lower;
406         PLpgSQL_expr *upper;
407         PLpgSQL_expr *step;                     /* NULL means default (ie, BY 1) */
408         int                     reverse;
409         List       *body;                       /* List of statements */
410 } PLpgSQL_stmt_fori;
411
412
413 /*
414  * PLpgSQL_stmt_forq represents a FOR statement running over a SQL query.
415  * It is the common supertype of PLpgSQL_stmt_fors, PLpgSQL_stmt_forc
416  * and PLpgSQL_dynfors.
417  */
418 typedef struct
419 {
420         int                     cmd_type;
421         int                     lineno;
422         char       *label;
423         PLpgSQL_rec *rec;
424         PLpgSQL_row *row;
425         List       *body;                       /* List of statements */
426 } PLpgSQL_stmt_forq;
427
428 typedef struct
429 {                                                               /* FOR statement running over SELECT    */
430         int                     cmd_type;
431         int                     lineno;
432         char       *label;
433         PLpgSQL_rec *rec;
434         PLpgSQL_row *row;
435         List       *body;                       /* List of statements */
436         /* end of fields that must match PLpgSQL_stmt_forq */
437         PLpgSQL_expr *query;
438 } PLpgSQL_stmt_fors;
439
440 typedef struct
441 {                                                               /* FOR statement running over cursor    */
442         int                     cmd_type;
443         int                     lineno;
444         char       *label;
445         PLpgSQL_rec *rec;
446         PLpgSQL_row *row;
447         List       *body;                       /* List of statements */
448         /* end of fields that must match PLpgSQL_stmt_forq */
449         int                     curvar;
450         PLpgSQL_expr *argquery;         /* cursor arguments if any */
451 } PLpgSQL_stmt_forc;
452
453 typedef struct
454 {                                                               /* FOR statement running over EXECUTE   */
455         int                     cmd_type;
456         int                     lineno;
457         char       *label;
458         PLpgSQL_rec *rec;
459         PLpgSQL_row *row;
460         List       *body;                       /* List of statements */
461         /* end of fields that must match PLpgSQL_stmt_forq */
462         PLpgSQL_expr *query;
463         List       *params;                     /* USING expressions */
464 } PLpgSQL_stmt_dynfors;
465
466
467 typedef struct
468 {                                                               /* OPEN a curvar                                        */
469         int                     cmd_type;
470         int                     lineno;
471         int                     curvar;
472         int                     cursor_options;
473         PLpgSQL_row *returntype;
474         PLpgSQL_expr *argquery;
475         PLpgSQL_expr *query;
476         PLpgSQL_expr *dynquery;
477 } PLpgSQL_stmt_open;
478
479
480 typedef struct
481 {                                                               /* FETCH or MOVE statement */
482         int                     cmd_type;
483         int                     lineno;
484         PLpgSQL_rec *rec;                       /* target, as record or row */
485         PLpgSQL_row *row;
486         int                     curvar;                 /* cursor variable to fetch from */
487         FetchDirection direction;       /* fetch direction */
488         int                     how_many;               /* count, if constant (expr is NULL) */
489         PLpgSQL_expr *expr;                     /* count, if expression */
490         bool            is_move;                /* is this a fetch or move? */
491 } PLpgSQL_stmt_fetch;
492
493
494 typedef struct
495 {                                                               /* CLOSE curvar                                         */
496         int                     cmd_type;
497         int                     lineno;
498         int                     curvar;
499 } PLpgSQL_stmt_close;
500
501
502 typedef struct
503 {                                                               /* EXIT or CONTINUE statement                   */
504         int                     cmd_type;
505         int                     lineno;
506         bool            is_exit;                /* Is this an exit or a continue? */
507         char       *label;                      /* NULL if it's an unlabelled EXIT/CONTINUE */
508         PLpgSQL_expr *cond;
509 } PLpgSQL_stmt_exit;
510
511
512 typedef struct
513 {                                                               /* RETURN statement                     */
514         int                     cmd_type;
515         int                     lineno;
516         PLpgSQL_expr *expr;
517         int                     retvarno;
518 } PLpgSQL_stmt_return;
519
520 typedef struct
521 {                                                               /* RETURN NEXT statement */
522         int                     cmd_type;
523         int                     lineno;
524         PLpgSQL_expr *expr;
525         int                     retvarno;
526 } PLpgSQL_stmt_return_next;
527
528 typedef struct
529 {                                                               /* RETURN QUERY statement */
530         int                     cmd_type;
531         int                     lineno;
532         PLpgSQL_expr *query;
533 } PLpgSQL_stmt_return_query;
534
535 typedef struct
536 {                                                               /* RAISE statement                      */
537         int                     cmd_type;
538         int                     lineno;
539         int                     elog_level;
540         char       *message;
541         List       *params;                     /* list of expressions */
542 } PLpgSQL_stmt_raise;
543
544
545 typedef struct
546 {                                                               /* Generic SQL statement to execute */
547         int                     cmd_type;
548         int                     lineno;
549         PLpgSQL_expr *sqlstmt;
550         bool            mod_stmt;               /* is the stmt INSERT/UPDATE/DELETE? */
551         /* note: mod_stmt is set when we plan the query */
552         bool            into;                   /* INTO supplied? */
553         bool            strict;                 /* INTO STRICT flag */
554         PLpgSQL_rec *rec;                       /* INTO target, if record */
555         PLpgSQL_row *row;                       /* INTO target, if row */
556 } PLpgSQL_stmt_execsql;
557
558
559 typedef struct
560 {                                                               /* Dynamic SQL string to execute */
561         int                     cmd_type;
562         int                     lineno;
563         PLpgSQL_expr *query;            /* string expression */
564         bool            into;                   /* INTO supplied? */
565         bool            strict;                 /* INTO STRICT flag */
566         PLpgSQL_rec *rec;                       /* INTO target, if record */
567         PLpgSQL_row *row;                       /* INTO target, if row */
568         List       *params;                     /* USING expressions */
569 } PLpgSQL_stmt_dynexecute;
570
571
572 typedef struct PLpgSQL_func_hashkey
573 {                                                               /* Hash lookup key for functions */
574         Oid                     funcOid;
575
576         /*
577          * For a trigger function, the OID of the relation triggered on is part of
578          * the hashkey --- we want to compile the trigger separately for each
579          * relation it is used with, in case the rowtype is different.  Zero if
580          * not called as a trigger.
581          */
582         Oid                     trigrelOid;
583
584         /*
585          * We include actual argument types in the hash key to support polymorphic
586          * PLpgSQL functions.  Be careful that extra positions are zeroed!
587          */
588         Oid                     argtypes[FUNC_MAX_ARGS];
589 } PLpgSQL_func_hashkey;
590
591
592 typedef struct PLpgSQL_function
593 {                                                               /* Complete compiled function     */
594         char       *fn_name;
595         Oid                     fn_oid;
596         TransactionId fn_xmin;
597         ItemPointerData fn_tid;
598         int                     fn_functype;
599         PLpgSQL_func_hashkey *fn_hashkey;       /* back-link to hashtable key */
600         MemoryContext fn_cxt;
601
602         Oid                     fn_rettype;
603         int                     fn_rettyplen;
604         bool            fn_retbyval;
605         FmgrInfo        fn_retinput;
606         Oid                     fn_rettypioparam;
607         bool            fn_retistuple;
608         bool            fn_retset;
609         bool            fn_readonly;
610
611         int                     fn_nargs;
612         int                     fn_argvarnos[FUNC_MAX_ARGS];
613         int                     out_param_varno;
614         int                     found_varno;
615         int                     new_varno;
616         int                     old_varno;
617         int                     tg_name_varno;
618         int                     tg_when_varno;
619         int                     tg_level_varno;
620         int                     tg_op_varno;
621         int                     tg_relid_varno;
622         int                     tg_relname_varno;
623         int                     tg_table_name_varno;
624         int                     tg_table_schema_varno;
625         int                     tg_nargs_varno;
626
627         int                     ndatums;
628         PLpgSQL_datum **datums;
629         PLpgSQL_stmt_block *action;
630
631         unsigned long use_count;
632 } PLpgSQL_function;
633
634
635 typedef struct
636 {                                                               /* Runtime execution data       */
637         Datum           retval;
638         bool            retisnull;
639         Oid                     rettype;                /* type of current retval */
640
641         Oid                     fn_rettype;             /* info about declared function rettype */
642         bool            retistuple;
643         bool            retisset;
644
645         bool            readonly_func;
646
647         TupleDesc       rettupdesc;
648         char       *exitlabel;          /* the "target" label of the current EXIT or
649                                                                  * CONTINUE stmt, if any */
650
651         Tuplestorestate *tuple_store;           /* SRFs accumulate results here */
652         MemoryContext tuple_store_cxt;
653         ReturnSetInfo *rsi;
654
655         int                     trig_nargs;
656         Datum      *trig_argv;
657
658         int                     found_varno;
659         int                     ndatums;
660         PLpgSQL_datum **datums;
661
662         /* temporary state for results from evaluation of query or expr */
663         SPITupleTable *eval_tuptable;
664         uint32          eval_processed;
665         Oid                     eval_lastoid;
666         ExprContext *eval_econtext; /* for executing simple expressions */
667         EState     *eval_estate;        /* EState containing eval_econtext */
668         long int        eval_estate_simple_id;  /* ID for eval_estate */
669
670         /* status information for error context reporting */
671         PLpgSQL_function *err_func; /* current func */
672         PLpgSQL_stmt *err_stmt;         /* current stmt */
673         const char *err_text;           /* additional state info */
674         void       *plugin_info;        /* reserved for use by optional plugin */
675 } PLpgSQL_execstate;
676
677
678 /*
679  * A PLpgSQL_plugin structure represents an instrumentation plugin.
680  * To instrument PL/pgSQL, a plugin library must access the rendezvous
681  * variable "PLpgSQL_plugin" and set it to point to a PLpgSQL_plugin struct.
682  * Typically the struct could just be static data in the plugin library.
683  * We expect that a plugin would do this at library load time (_PG_init()).
684  * It must also be careful to set the rendezvous variable back to NULL
685  * if it is unloaded (_PG_fini()).
686  *
687  * This structure is basically a collection of function pointers --- at
688  * various interesting points in pl_exec.c, we call these functions
689  * (if the pointers are non-NULL) to give the plugin a chance to watch
690  * what we are doing.
691  *
692  *      func_setup is called when we start a function, before we've initialized
693  *      the local variables defined by the function.
694  *
695  *      func_beg is called when we start a function, after we've initialized
696  *      the local variables.
697  *
698  *      func_end is called at the end of a function.
699  *
700  *      stmt_beg and stmt_end are called before and after (respectively) each
701  *      statement.
702  *
703  * Also, immediately before any call to func_setup, PL/pgSQL fills in the
704  * error_callback and assign_expr fields with pointers to its own
705  * plpgsql_exec_error_callback and exec_assign_expr functions.  This is
706  * a somewhat ad-hoc expedient to simplify life for debugger plugins.
707  */
708
709 typedef struct
710 {
711         /* Function pointers set up by the plugin */
712         void            (*func_setup) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
713         void            (*func_beg) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
714         void            (*func_end) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
715         void            (*stmt_beg) (PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt);
716         void            (*stmt_end) (PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt);
717
718         /* Function pointers set by PL/pgSQL itself */
719         void            (*error_callback) (void *arg);
720         void            (*assign_expr) (PLpgSQL_execstate *estate, PLpgSQL_datum *target,
721                                                                                         PLpgSQL_expr *expr);
722 } PLpgSQL_plugin;
723
724
725 /**********************************************************************
726  * Global variable declarations
727  **********************************************************************/
728
729 extern bool plpgsql_DumpExecTree;
730 extern bool plpgsql_SpaceScanned;
731 extern int      plpgsql_nDatums;
732 extern PLpgSQL_datum **plpgsql_Datums;
733
734 extern int      plpgsql_error_lineno;
735 extern char *plpgsql_error_funcname;
736
737 /* linkage to the real yytext variable */
738 extern char *plpgsql_base_yytext;
739
740 #define yytext plpgsql_base_yytext
741
742 extern PLpgSQL_function *plpgsql_curr_compile;
743 extern bool plpgsql_check_syntax;
744 extern MemoryContext compile_tmp_cxt;
745
746 extern PLpgSQL_plugin **plugin_ptr;
747
748 /**********************************************************************
749  * Function declarations
750  **********************************************************************/
751
752 /* ----------
753  * Functions in pl_comp.c
754  * ----------
755  */
756 extern PLpgSQL_function *plpgsql_compile(FunctionCallInfo fcinfo,
757                                 bool forValidator);
758 extern int      plpgsql_parse_word(const char *word);
759 extern int      plpgsql_parse_dblword(const char *word);
760 extern int      plpgsql_parse_tripword(const char *word);
761 extern int      plpgsql_parse_wordtype(char *word);
762 extern int      plpgsql_parse_dblwordtype(char *word);
763 extern int      plpgsql_parse_tripwordtype(char *word);
764 extern int      plpgsql_parse_wordrowtype(char *word);
765 extern int      plpgsql_parse_dblwordrowtype(char *word);
766 extern PLpgSQL_type *plpgsql_parse_datatype(const char *string);
767 extern PLpgSQL_type *plpgsql_build_datatype(Oid typeOid, int32 typmod);
768 extern PLpgSQL_variable *plpgsql_build_variable(const char *refname, int lineno,
769                                            PLpgSQL_type *dtype,
770                                            bool add2namespace);
771 extern PLpgSQL_rec *plpgsql_build_record(const char *refname, int lineno,
772                                                                                  bool add2namespace);
773 extern PLpgSQL_condition *plpgsql_parse_err_condition(char *condname);
774 extern void plpgsql_adddatum(PLpgSQL_datum *new);
775 extern int      plpgsql_add_initdatums(int **varnos);
776 extern void plpgsql_HashTableInit(void);
777 extern void plpgsql_compile_error_callback(void *arg);
778
779 /* ----------
780  * Functions in pl_handler.c
781  * ----------
782  */
783 extern void _PG_init(void);
784 extern Datum plpgsql_call_handler(PG_FUNCTION_ARGS);
785 extern Datum plpgsql_validator(PG_FUNCTION_ARGS);
786
787 /* ----------
788  * Functions in pl_exec.c
789  * ----------
790  */
791 extern Datum plpgsql_exec_function(PLpgSQL_function *func,
792                                           FunctionCallInfo fcinfo);
793 extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function *func,
794                                          TriggerData *trigdata);
795 extern void plpgsql_xact_cb(XactEvent event, void *arg);
796 extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid,
797                                    SubTransactionId parentSubid, void *arg);
798
799 /* ----------
800  * Functions for the dynamic string handling in pl_funcs.c
801  * ----------
802  */
803 extern void plpgsql_dstring_init(PLpgSQL_dstring *ds);
804 extern void plpgsql_dstring_free(PLpgSQL_dstring *ds);
805 extern void plpgsql_dstring_append(PLpgSQL_dstring *ds, const char *str);
806 extern void plpgsql_dstring_append_char(PLpgSQL_dstring *ds, char c);
807 extern char *plpgsql_dstring_get(PLpgSQL_dstring *ds);
808
809 /* ----------
810  * Functions for namestack handling in pl_funcs.c
811  * ----------
812  */
813 extern void plpgsql_ns_init(void);
814 extern bool plpgsql_ns_setlocal(bool flag);
815 extern void plpgsql_ns_push(const char *label);
816 extern void plpgsql_ns_pop(void);
817 extern void plpgsql_ns_additem(int itemtype, int itemno, const char *name);
818 extern PLpgSQL_nsitem *plpgsql_ns_lookup(const char *name1, const char *name2,
819                                                                                  const char *name3, int *names_used);
820 extern PLpgSQL_nsitem *plpgsql_ns_lookup_label(const char *name);
821 extern void plpgsql_ns_rename(char *oldname, char *newname);
822
823 /* ----------
824  * Other functions in pl_funcs.c
825  * ----------
826  */
827 extern void plpgsql_convert_ident(const char *s, char **output, int numidents);
828 extern const char *plpgsql_stmt_typename(PLpgSQL_stmt *stmt);
829 extern void plpgsql_dumptree(PLpgSQL_function *func);
830
831 /* ----------
832  * Externs in gram.y and scan.l
833  * ----------
834  */
835 extern PLpgSQL_expr *plpgsql_read_expression(int until, const char *expected);
836 extern int      plpgsql_yyparse(void);
837 extern int      plpgsql_base_yylex(void);
838 extern int      plpgsql_yylex(void);
839 extern void plpgsql_push_back_token(int token);
840 extern void plpgsql_yyerror(const char *message);
841 extern int      plpgsql_scanner_lineno(void);
842 extern void plpgsql_scanner_init(const char *str, int functype);
843 extern void plpgsql_scanner_finish(void);
844 extern char *plpgsql_get_string_value(void);
845
846 #endif   /* PLPGSQL_H */