1 /**********************************************************************
2 * pl_handler.c - Handler for the PL/pgSQL
6 * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.15 2003/07/27 17:10:07 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 **********************************************************************/
41 #include "access/heapam.h"
42 #include "catalog/pg_proc.h"
43 #include "catalog/pg_type.h"
44 #include "utils/builtins.h"
45 #include "utils/syscache.h"
49 * plpgsql_call_handler
51 * This is the only visible function of the PL interpreter.
52 * The PostgreSQL function manager and trigger manager
53 * call this function for execution of PL/pgSQL procedures.
56 PG_FUNCTION_INFO_V1(plpgsql_call_handler);
59 plpgsql_call_handler(PG_FUNCTION_ARGS)
61 PLpgSQL_function *func;
65 * Connect to SPI manager
67 if (SPI_connect() != SPI_OK_CONNECT)
68 elog(ERROR, "SPI_connect failed");
70 /* Find or compile the function */
71 func = plpgsql_compile(fcinfo);
74 * Determine if called as function or trigger and call appropriate
77 if (CALLED_AS_TRIGGER(fcinfo))
78 retval = PointerGetDatum(plpgsql_exec_trigger(func,
79 (TriggerData *) fcinfo->context));
81 retval = plpgsql_exec_function(func, fcinfo);
84 * Disconnect from SPI manager
86 if (SPI_finish() != SPI_OK_FINISH)
87 elog(ERROR, "SPI_finish failed");