1 /**********************************************************************
2 * plpgsql.h - Definitions for the PL/pgSQL
6 * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.26 2002/08/30 00:28:41 tgl Exp $
8 * This software is copyrighted by Jan Wieck - Hamburg.
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.
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
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.
36 **********************************************************************/
43 #include "miscadmin.h"
44 #include "executor/spi.h"
45 #include "commands/trigger.h"
46 #include "utils/tuplestore.h"
48 /**********************************************************************
50 **********************************************************************/
53 * Compilers namestack item types
62 PLPGSQL_NSTYPE_RECFIELD
66 * Datum array node types
74 PLPGSQL_DTYPE_RECFIELD,
80 * Execution tree node types
95 PLPGSQL_STMT_RETURN_NEXT,
98 PLPGSQL_STMT_DYNEXECUTE,
100 PLPGSQL_STMT_GETDIAG,
108 * Execution node return codes
119 * GET DIAGNOSTICS system attrs
124 PLPGSQL_GETDIAG_ROW_COUNT,
125 PLPGSQL_GETDIAG_RESULT_OID
129 /**********************************************************************
130 * Node and structure definitions
131 **********************************************************************/
135 { /* Dynamic string control structure */
143 { /* Postgres base data type */
155 { /* Generic datum array item */
162 { /* SQL Query to plan and execute */
167 Node *plan_simple_expr;
168 Oid plan_simple_type;
176 { /* Local variable */
182 PLpgSQL_type *datatype;
185 PLpgSQL_expr *default_val;
186 PLpgSQL_expr *cursor_explicit_expr;
187 int cursor_explicit_argrow;
210 { /* Record of undefined structure */
224 { /* Field in record */
233 { /* Positional argument to trigger */
236 PLpgSQL_expr *argnum;
241 { /* Item in the compilers namestack */
248 typedef struct PLpgSQL_ns
249 { /* Compiler namestack level */
252 PLpgSQL_nsitem **items;
253 struct PLpgSQL_ns *upper;
258 { /* List of execution nodes */
261 struct PLpgSQL_stmt **stmts;
266 { /* Generic execution node */
273 { /* Block of statements */
280 } PLpgSQL_stmt_block;
284 { /* Assign statement */
289 } PLpgSQL_stmt_assign;
293 { /* Get Diagnostics item */
294 int item; /* id for diagnostic value desired */
295 int target; /* where to assign it */
299 { /* Get Diagnostics statement */
303 PLpgSQL_diag_item *dtitems;
304 } PLpgSQL_stmt_getdiag;
312 PLpgSQL_stmts *true_body;
313 PLpgSQL_stmts *false_body;
318 { /* Unconditional LOOP statement */
327 { /* WHILE cond LOOP statement */
333 } PLpgSQL_stmt_while;
337 { /* FOR statement with integer loopvar */
350 { /* FOR statement running over SELECT */
362 { /* FOR statement running over EXECUTE */
370 } PLpgSQL_stmt_dynfors;
374 { /* SELECT ... INTO statement */
380 } PLpgSQL_stmt_select;
384 { /* OPEN a curvar */
388 PLpgSQL_row *returntype;
389 PLpgSQL_expr *argquery;
391 PLpgSQL_expr *dynquery;
396 { /* FETCH curvar INTO statement */
402 } PLpgSQL_stmt_fetch;
410 } PLpgSQL_stmt_close;
414 { /* EXIT statement */
423 { /* RETURN statement */
428 } PLpgSQL_stmt_return;
431 { /* RETURN NEXT statement */
437 } PLpgSQL_stmt_return_next;
440 { /* RAISE statement */
447 } PLpgSQL_stmt_raise;
451 { /* Generic SQL statement to execute */
454 PLpgSQL_expr *sqlstmt;
455 } PLpgSQL_stmt_execsql;
459 { /* Dynamic SQL string to execute */
463 } PLpgSQL_stmt_dynexecute;
466 typedef struct PLpgSQL_function
467 { /* Complete compiled function */
470 TransactionId fn_xmin;
477 FmgrInfo fn_retinput;
483 int fn_argvarnos[FUNC_MAX_ARGS];
492 int tg_relname_varno;
496 PLpgSQL_datum **datums;
497 PLpgSQL_stmt_block *action;
499 struct PLpgSQL_function *next; /* for chaining list of functions */
504 { /* Runtime execution data */
507 Oid rettype; /* type of current retval */
509 Oid fn_rettype; /* info about declared function rettype */
513 TupleDesc rettupdesc;
516 Tuplestorestate *tuple_store; /* SRFs accumulate results here */
517 MemoryContext tuple_store_cxt;
525 PLpgSQL_datum **datums;
527 /* temporary state for results from evaluation of query or expr */
528 SPITupleTable *eval_tuptable;
529 uint32 eval_processed;
531 ExprContext *eval_econtext;
535 /**********************************************************************
536 * Global variable declarations
537 **********************************************************************/
539 extern int plpgsql_DumpExecTree;
540 extern int plpgsql_SpaceScanned;
541 extern int plpgsql_nDatums;
542 extern PLpgSQL_datum **plpgsql_Datums;
544 extern int plpgsql_error_lineno;
545 extern char *plpgsql_error_funcname;
547 /* linkage to the real yytext and yylineno variables */
548 extern char *plpgsql_base_yytext;
550 #define plpgsql_yytext plpgsql_base_yytext
551 extern int plpgsql_base_yylineno;
553 #define plpgsql_yylineno plpgsql_base_yylineno
555 extern PLpgSQL_function *plpgsql_curr_compile;
557 /**********************************************************************
558 * Function declarations
559 **********************************************************************/
562 * Functions in pl_comp.c
565 extern PLpgSQL_function *plpgsql_compile(Oid fn_oid, int functype);
566 extern int plpgsql_parse_word(char *word);
567 extern int plpgsql_parse_dblword(char *word);
568 extern int plpgsql_parse_tripword(char *word);
569 extern int plpgsql_parse_wordtype(char *word);
570 extern int plpgsql_parse_dblwordtype(char *word);
571 extern int plpgsql_parse_wordrowtype(char *word);
572 extern PLpgSQL_type *plpgsql_parse_datatype(char *string);
573 extern void plpgsql_adddatum(PLpgSQL_datum * new);
574 extern int plpgsql_add_initdatums(int **varnos);
575 extern void plpgsql_yyerror(const char *s);
578 * Functions in pl_handler.c
581 extern Datum plpgsql_call_handler(PG_FUNCTION_ARGS);
584 * Functions in pl_exec.c
587 extern Datum plpgsql_exec_function(PLpgSQL_function * func,
588 FunctionCallInfo fcinfo);
589 extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function * func,
590 TriggerData *trigdata);
594 * Functions for the dynamic string handling in pl_funcs.c
597 extern void plpgsql_dstring_init(PLpgSQL_dstring * ds);
598 extern void plpgsql_dstring_free(PLpgSQL_dstring * ds);
599 extern void plpgsql_dstring_append(PLpgSQL_dstring * ds, char *str);
600 extern char *plpgsql_dstring_get(PLpgSQL_dstring * ds);
603 * Functions for the namestack handling in pl_funcs.c
606 extern void plpgsql_ns_init(void);
607 extern bool plpgsql_ns_setlocal(bool flag);
608 extern void plpgsql_ns_push(char *label);
609 extern void plpgsql_ns_pop(void);
610 extern void plpgsql_ns_additem(int itemtype, int itemno, char *name);
611 extern PLpgSQL_nsitem *plpgsql_ns_lookup(char *name, char *nsname);
612 extern void plpgsql_ns_rename(char *oldname, char *newname);
615 * Other functions in pl_funcs.c
618 extern void plpgsql_convert_ident(const char *s, char **output, int numidents);
619 extern const char *plpgsql_stmt_typename(PLpgSQL_stmt * stmt);
620 extern void plpgsql_dumptree(PLpgSQL_function * func);
623 * Externs in gram.y and scan.l
626 extern PLpgSQL_expr *plpgsql_read_expression(int until, const char *expected);
627 extern int plpgsql_yyparse(void);
628 extern int plpgsql_base_yylex(void);
629 extern int plpgsql_yylex(void);
630 extern void plpgsql_push_back_token(int token);
631 extern void plpgsql_setinput(char *s, int functype);
633 #endif /* PLPGSQL_H */