1 /**********************************************************************
2 * plpgsql.h - Definitions for the PL/pgSQL
6 * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.29 2002/11/10 00:35:58 momjian 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,
109 * Execution node return codes
120 * GET DIAGNOSTICS system attrs
125 PLPGSQL_GETDIAG_ROW_COUNT,
126 PLPGSQL_GETDIAG_RESULT_OID
130 /**********************************************************************
131 * Node and structure definitions
132 **********************************************************************/
136 { /* Dynamic string control structure */
144 { /* Postgres base data type */
156 { /* Generic datum array item */
163 { /* SQL Query to plan and execute */
168 Node *plan_simple_expr;
169 Oid plan_simple_type;
177 { /* Local variable */
183 PLpgSQL_type *datatype;
186 PLpgSQL_expr *default_val;
187 PLpgSQL_expr *cursor_explicit_expr;
188 int cursor_explicit_argrow;
211 { /* Record of undefined structure */
225 { /* Field in record */
234 { /* Positional argument to trigger */
237 PLpgSQL_expr *argnum;
242 { /* Item in the compilers namestack */
249 typedef struct PLpgSQL_ns
250 { /* Compiler namestack level */
253 PLpgSQL_nsitem **items;
254 struct PLpgSQL_ns *upper;
259 { /* List of execution nodes */
262 struct PLpgSQL_stmt **stmts;
267 { /* Generic execution node */
274 { /* Block of statements */
281 } PLpgSQL_stmt_block;
285 { /* Assign statement */
290 } PLpgSQL_stmt_assign;
293 { /* PERFORM statement */
297 } PLpgSQL_stmt_perform;
300 { /* Get Diagnostics item */
301 int item; /* id for diagnostic value desired */
302 int target; /* where to assign it */
306 { /* Get Diagnostics statement */
310 PLpgSQL_diag_item *dtitems;
311 } PLpgSQL_stmt_getdiag;
319 PLpgSQL_stmts *true_body;
320 PLpgSQL_stmts *false_body;
325 { /* Unconditional LOOP statement */
334 { /* WHILE cond LOOP statement */
340 } PLpgSQL_stmt_while;
344 { /* FOR statement with integer loopvar */
357 { /* FOR statement running over SELECT */
369 { /* FOR statement running over EXECUTE */
377 } PLpgSQL_stmt_dynfors;
381 { /* SELECT ... INTO statement */
387 } PLpgSQL_stmt_select;
391 { /* OPEN a curvar */
395 PLpgSQL_row *returntype;
396 PLpgSQL_expr *argquery;
398 PLpgSQL_expr *dynquery;
403 { /* FETCH curvar INTO statement */
409 } PLpgSQL_stmt_fetch;
417 } PLpgSQL_stmt_close;
421 { /* EXIT statement */
430 { /* RETURN statement */
435 } PLpgSQL_stmt_return;
438 { /* RETURN NEXT statement */
444 } PLpgSQL_stmt_return_next;
447 { /* RAISE statement */
454 } PLpgSQL_stmt_raise;
458 { /* Generic SQL statement to execute */
461 PLpgSQL_expr *sqlstmt;
462 } PLpgSQL_stmt_execsql;
466 { /* Dynamic SQL string to execute */
470 } PLpgSQL_stmt_dynexecute;
473 typedef struct PLpgSQL_function
474 { /* Complete compiled function */
477 TransactionId fn_xmin;
484 FmgrInfo fn_retinput;
490 int fn_argvarnos[FUNC_MAX_ARGS];
499 int tg_relname_varno;
503 PLpgSQL_datum **datums;
504 PLpgSQL_stmt_block *action;
506 struct PLpgSQL_function *next; /* for chaining list of functions */
511 { /* Runtime execution data */
514 Oid rettype; /* type of current retval */
516 Oid fn_rettype; /* info about declared function rettype */
520 TupleDesc rettupdesc;
523 Tuplestorestate *tuple_store; /* SRFs accumulate results here */
524 MemoryContext tuple_store_cxt;
532 PLpgSQL_datum **datums;
534 /* temporary state for results from evaluation of query or expr */
535 SPITupleTable *eval_tuptable;
536 uint32 eval_processed;
538 ExprContext *eval_econtext;
542 /**********************************************************************
543 * Global variable declarations
544 **********************************************************************/
546 extern int plpgsql_DumpExecTree;
547 extern int plpgsql_SpaceScanned;
548 extern int plpgsql_nDatums;
549 extern PLpgSQL_datum **plpgsql_Datums;
551 extern int plpgsql_error_lineno;
552 extern char *plpgsql_error_funcname;
554 /* linkage to the real yytext and yylineno variables */
555 extern char *plpgsql_base_yytext;
557 #define plpgsql_yytext plpgsql_base_yytext
558 extern int plpgsql_base_yylineno;
560 #define plpgsql_yylineno plpgsql_base_yylineno
562 extern PLpgSQL_function *plpgsql_curr_compile;
564 /**********************************************************************
565 * Function declarations
566 **********************************************************************/
569 * Functions in pl_comp.c
572 extern PLpgSQL_function *plpgsql_compile(Oid fn_oid, int functype);
573 extern int plpgsql_parse_word(char *word);
574 extern int plpgsql_parse_dblword(char *word);
575 extern int plpgsql_parse_tripword(char *word);
576 extern int plpgsql_parse_wordtype(char *word);
577 extern int plpgsql_parse_dblwordtype(char *word);
578 extern int plpgsql_parse_tripwordtype(char *word);
579 extern int plpgsql_parse_wordrowtype(char *word);
580 extern int plpgsql_parse_dblwordrowtype(char *word);
581 extern PLpgSQL_type *plpgsql_parse_datatype(char *string);
582 extern void plpgsql_adddatum(PLpgSQL_datum * new);
583 extern int plpgsql_add_initdatums(int **varnos);
584 extern void plpgsql_yyerror(const char *s);
587 * Functions in pl_handler.c
590 extern Datum plpgsql_call_handler(PG_FUNCTION_ARGS);
593 * Functions in pl_exec.c
596 extern Datum plpgsql_exec_function(PLpgSQL_function * func,
597 FunctionCallInfo fcinfo);
598 extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function * func,
599 TriggerData *trigdata);
603 * Functions for the dynamic string handling in pl_funcs.c
606 extern void plpgsql_dstring_init(PLpgSQL_dstring * ds);
607 extern void plpgsql_dstring_free(PLpgSQL_dstring * ds);
608 extern void plpgsql_dstring_append(PLpgSQL_dstring * ds, char *str);
609 extern char *plpgsql_dstring_get(PLpgSQL_dstring * ds);
612 * Functions for the namestack handling in pl_funcs.c
615 extern void plpgsql_ns_init(void);
616 extern bool plpgsql_ns_setlocal(bool flag);
617 extern void plpgsql_ns_push(char *label);
618 extern void plpgsql_ns_pop(void);
619 extern void plpgsql_ns_additem(int itemtype, int itemno, char *name);
620 extern PLpgSQL_nsitem *plpgsql_ns_lookup(char *name, char *nsname);
621 extern void plpgsql_ns_rename(char *oldname, char *newname);
624 * Other functions in pl_funcs.c
627 extern void plpgsql_convert_ident(const char *s, char **output, int numidents);
628 extern const char *plpgsql_stmt_typename(PLpgSQL_stmt * stmt);
629 extern void plpgsql_dumptree(PLpgSQL_function * func);
632 * Externs in gram.y and scan.l
635 extern PLpgSQL_expr *plpgsql_read_expression(int until, const char *expected);
636 extern int plpgsql_yyparse(void);
637 extern int plpgsql_base_yylex(void);
638 extern int plpgsql_yylex(void);
639 extern void plpgsql_push_back_token(int token);
640 extern void plpgsql_setinput(char *s, int functype);
642 #endif /* PLPGSQL_H */