1 /**********************************************************************
2 * plpgsql.h - Definitions for the PL/pgSQL
6 * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.20 2001/10/25 05:50:20 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 "executor/spi.h"
44 #include "commands/trigger.h"
46 /**********************************************************************
48 **********************************************************************/
51 * Compilers namestack item types
60 PLPGSQL_NSTYPE_RECFIELD
64 * Datum array node types
72 PLPGSQL_DTYPE_RECFIELD,
78 * Execution tree node types
95 PLPGSQL_STMT_DYNEXECUTE,
105 * Execution node return codes
116 * GET DIAGNOSTICS system attrs
121 PLPGSQL_GETDIAG_ROW_COUNT,
122 PLPGSQL_GETDIAG_RESULT_OID
126 /**********************************************************************
127 * Node and structure definitions
128 **********************************************************************/
132 { /* Dynamic string control structure */
140 { /* Postgres base data type */
152 { /* Generic datum array item */
159 { /* SQL Query to plan and execute */
164 Node *plan_simple_expr;
165 Oid plan_simple_type;
173 { /* Local variable */
179 PLpgSQL_type *datatype;
182 PLpgSQL_expr *default_val;
183 PLpgSQL_expr *cursor_explicit_expr;
184 int cursor_explicit_argrow;
207 { /* Record of undefined structure */
221 { /* Field in record */
230 { /* Positional argument to trigger */
233 PLpgSQL_expr *argnum;
238 { /* Item in the compilers namestack */
245 typedef struct PLpgSQL_ns
246 { /* Compiler namestack level */
249 PLpgSQL_nsitem **items;
250 struct PLpgSQL_ns *upper;
255 { /* List of execution nodes */
258 struct PLpgSQL_stmt **stmts;
263 { /* Generic execution node */
270 { /* Block of statements */
277 } PLpgSQL_stmt_block;
281 { /* Assign statement */
286 } PLpgSQL_stmt_assign;
290 { /* Get Diagnostics item */
291 int item; /* id for diagnostic value desired */
292 int target; /* where to assign it */
296 { /* Get Diagnostics statement */
300 PLpgSQL_diag_item *dtitems;
301 } PLpgSQL_stmt_getdiag;
309 PLpgSQL_stmts *true_body;
310 PLpgSQL_stmts *false_body;
315 { /* Unconditional LOOP statement */
324 { /* WHILE cond LOOP statement */
330 } PLpgSQL_stmt_while;
334 { /* FOR statement with integer loopvar */
347 { /* FOR statement running over SELECT */
359 { /* FOR statement running over EXECUTE */
367 } PLpgSQL_stmt_dynfors;
371 { /* SELECT ... INTO statement */
377 } PLpgSQL_stmt_select;
381 { /* OPEN a curvar */
385 PLpgSQL_row *returntype;
386 PLpgSQL_expr *argquery;
388 PLpgSQL_expr *dynquery;
393 { /* FETCH curvar INTO statement */
399 } PLpgSQL_stmt_fetch;
407 } PLpgSQL_stmt_close;
411 { /* EXIT statement */
420 { /* RETURN statement */
426 } PLpgSQL_stmt_return;
430 { /* RAISE statement */
437 } PLpgSQL_stmt_raise;
441 { /* Generic SQL statement to execute */
444 PLpgSQL_expr *sqlstmt;
445 } PLpgSQL_stmt_execsql;
449 { /* Dynamic SQL string to execute */
453 } PLpgSQL_stmt_dynexecute;
456 typedef struct PLpgSQL_function
457 { /* Complete compiled function */
460 TransactionId fn_xmin;
467 FmgrInfo fn_retinput;
473 int fn_argvarnos[FUNC_MAX_ARGS];
482 int tg_relname_varno;
486 PLpgSQL_datum **datums;
487 PLpgSQL_stmt_block *action;
489 struct PLpgSQL_function *next; /* for chaining list of functions */
494 { /* Runtime execution data */
499 TupleDesc rettupdesc;
508 PLpgSQL_datum **datums;
510 /* temporary state for results from evaluation of query or expr */
511 SPITupleTable *eval_tuptable;
512 uint32 eval_processed;
514 ExprContext *eval_econtext;
518 /**********************************************************************
519 * Global variable declarations
520 **********************************************************************/
522 extern int plpgsql_DumpExecTree;
523 extern int plpgsql_SpaceScanned;
524 extern int plpgsql_nDatums;
525 extern PLpgSQL_datum **plpgsql_Datums;
527 extern int plpgsql_error_lineno;
528 extern char *plpgsql_error_funcname;
530 /* linkage to the real yytext and yylineno variables */
531 extern char *plpgsql_base_yytext;
533 #define plpgsql_yytext plpgsql_base_yytext
534 extern int plpgsql_base_yylineno;
536 #define plpgsql_yylineno plpgsql_base_yylineno
538 extern PLpgSQL_function *plpgsql_curr_compile;
540 /**********************************************************************
541 * Function declarations
542 **********************************************************************/
545 * Functions in pl_comp.c
548 extern PLpgSQL_function *plpgsql_compile(Oid fn_oid, int functype);
549 extern int plpgsql_parse_word(char *word);
550 extern int plpgsql_parse_dblword(char *string);
551 extern int plpgsql_parse_tripword(char *string);
552 extern int plpgsql_parse_wordtype(char *string);
553 extern int plpgsql_parse_dblwordtype(char *string);
554 extern int plpgsql_parse_wordrowtype(char *string);
555 extern PLpgSQL_type *plpgsql_parse_datatype(char *string);
556 extern void plpgsql_adddatum(PLpgSQL_datum * new);
557 extern int plpgsql_add_initdatums(int **varnos);
558 extern void plpgsql_yyerror(const char *s);
561 * Functions in pl_handler.c
564 extern Datum plpgsql_call_handler(PG_FUNCTION_ARGS);
567 * Functions in pl_exec.c
570 extern Datum plpgsql_exec_function(PLpgSQL_function * func,
571 FunctionCallInfo fcinfo);
572 extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function * func,
573 TriggerData *trigdata);
577 * Functions for the dynamic string handling in pl_funcs.c
580 extern void plpgsql_dstring_init(PLpgSQL_dstring * ds);
581 extern void plpgsql_dstring_free(PLpgSQL_dstring * ds);
582 extern void plpgsql_dstring_append(PLpgSQL_dstring * ds, char *str);
583 extern char *plpgsql_dstring_get(PLpgSQL_dstring * ds);
586 * Functions for the namestack handling in pl_funcs.c
589 extern void plpgsql_ns_init(void);
590 extern bool plpgsql_ns_setlocal(bool flag);
591 extern void plpgsql_ns_push(char *label);
592 extern void plpgsql_ns_pop(void);
593 extern void plpgsql_ns_additem(int itemtype, int itemno, char *name);
594 extern PLpgSQL_nsitem *plpgsql_ns_lookup(char *name, char *nsname);
595 extern void plpgsql_ns_rename(char *oldname, char *newname);
598 * Other functions in pl_funcs.c
601 extern void plpgsql_dumptree(PLpgSQL_function * func);
602 extern char *plpgsql_tolower(char *s);
605 * Externs in gram.y and scan.l
608 extern PLpgSQL_expr *plpgsql_read_expression(int until, char *s);
609 extern int plpgsql_yyparse(void);
610 extern int plpgsql_base_yylex(void);
611 extern int plpgsql_yylex(void);
612 extern void plpgsql_push_back_token(int token);
613 extern void plpgsql_setinput(char *s, int functype);
614 #endif /* PLPGSQL_H */