PostgreSQL Source Code git master
|
#include "postgres.h"
#include <ctype.h>
#include "access/htup_details.h"
#include "catalog/namespace.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "nodes/makefuncs.h"
#include "parser/parse_node.h"
#include "plpgsql.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/regproc.h"
#include "utils/syscache.h"
#include "utils/typcache.h"
#include "plerrcodes.h"
Go to the source code of this file.
Data Structures | |
struct | ExceptionLabelMap |
struct | compile_error_callback_arg |
Variables | |
static int | datums_alloc |
int | plpgsql_nDatums |
PLpgSQL_datum ** | plpgsql_Datums |
static int | datums_last |
char * | plpgsql_error_funcname |
bool | plpgsql_DumpExecTree = false |
bool | plpgsql_check_syntax = false |
PLpgSQL_function * | plpgsql_curr_compile |
MemoryContext | plpgsql_compile_tmp_cxt |
static const ExceptionLabelMap | exception_label_map [] |
|
static |
Definition at line 930 of file pl_comp.c.
References function, lappend(), list_make1, llast, NIL, palloc0(), PLPGSQL_STMT_BLOCK, and PLPGSQL_STMT_RETURN.
Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().
|
static |
Definition at line 905 of file pl_comp.c.
References ereport, errcode(), errmsg(), ERROR, name, plpgsql_ns_additem(), plpgsql_ns_lookup(), and plpgsql_ns_top().
Referenced by plpgsql_compile_callback().
|
static |
Definition at line 1964 of file pl_comp.c.
References PLpgSQL_type::atttypmod, PLpgSQL_type::collation, TypeCacheEntry::domainBaseType, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), get_base_element_type(), GETSTRUCT(), lookup_type_cache(), NameStr, OidIsValid, PLpgSQL_type::origtypname, palloc(), PLPGSQL_TTYPE_PSEUDO, PLPGSQL_TTYPE_REC, PLPGSQL_TTYPE_SCALAR, pstrdup(), PLpgSQL_type::tcache, PLpgSQL_type::ttype, TypeCacheEntry::tupDesc, PLpgSQL_type::tupdesc_id, TypeCacheEntry::tupDesc_identifier, PLpgSQL_type::typbyval, type_is_rowtype(), TYPECACHE_DOMAIN_BASE_INFO, TYPECACHE_TUPDESC, PLpgSQL_type::typisarray, PLpgSQL_type::typlen, PLpgSQL_type::typname, PLpgSQL_type::typoid, TypeCacheEntry::typtype, and PLpgSQL_type::typtype.
Referenced by plpgsql_build_datatype(), plpgsql_compile_callback(), and plpgsql_parse_cwordtype().
|
static |
Definition at line 1828 of file pl_comp.c.
References Assert(), CreateTemplateTupleDesc(), PLpgSQL_variable::dno, PLpgSQL_variable::dtype, PLpgSQL_row::dtype, elog, ERROR, PLpgSQL_row::fieldnames, i, InvalidOid, PLpgSQL_variable::isconst, PLpgSQL_row::lineno, PLpgSQL_row::nfields, palloc(), palloc0(), PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, PLpgSQL_variable::refname, PLpgSQL_row::refname, PLpgSQL_row::rowtupdesc, TupleDescInitEntry(), TupleDescInitEntryCollation(), and PLpgSQL_row::varnos.
Referenced by plpgsql_compile_callback().
|
static |
Definition at line 1231 of file pl_comp.c.
References Assert(), bms_add_member(), PLpgSQL_function::cur_estate, PLpgSQL_execstate::datums, PLpgSQL_function::fn_cxt, PLpgSQL_expr::func, Param::location, makeNode, MemoryContextSwitchTo(), PARAM_EXTERN, Param::paramid, Param::paramkind, PLpgSQL_expr::paramnos, Param::paramtype, and plpgsql_exec_get_datum_type_info().
Referenced by plpgsql_param_ref(), and resolve_column_ref().
int plpgsql_add_initdatums | ( | int ** | varnos | ) |
Definition at line 2268 of file pl_comp.c.
References datums_last, PLpgSQL_datum::dno, i, palloc(), plpgsql_Datums, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_VAR, and plpgsql_nDatums.
void plpgsql_adddatum | ( | PLpgSQL_datum * | newdatum | ) |
Definition at line 2207 of file pl_comp.c.
References datums_alloc, PLpgSQL_datum::dno, plpgsql_Datums, plpgsql_nDatums, and repalloc().
Referenced by plpgsql_build_recfield(), plpgsql_build_record(), plpgsql_build_variable(), and plpgsql_compile_callback().
PLpgSQL_type * plpgsql_build_datatype | ( | Oid | typeOid, |
int32 | typmod, | ||
Oid | collation, | ||
TypeName * | origtypname | ||
) |
Definition at line 1942 of file pl_comp.c.
References build_datatype(), elog, ERROR, HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), and SearchSysCache1().
Referenced by exec_stmt_case(), plpgsql_build_datatype_arrayof(), plpgsql_compile_callback(), plpgsql_compile_inline(), plpgsql_parse_cwordrowtype(), and plpgsql_parse_wordrowtype().
PLpgSQL_type * plpgsql_build_datatype_arrayof | ( | PLpgSQL_type * | dtype | ) |
Definition at line 2076 of file pl_comp.c.
References PLpgSQL_type::atttypmod, PLpgSQL_type::collation, ereport, errcode(), errmsg(), ERROR, format_type_be(), get_array_type(), OidIsValid, plpgsql_build_datatype(), PLpgSQL_type::typisarray, and PLpgSQL_type::typoid.
PLpgSQL_recfield * plpgsql_build_recfield | ( | PLpgSQL_rec * | rec, |
const char * | fldname | ||
) |
Definition at line 1895 of file pl_comp.c.
References Assert(), PLpgSQL_rec::dno, PLpgSQL_recfield::dno, PLpgSQL_recfield::dtype, PLpgSQL_recfield::fieldname, PLpgSQL_rec::firstfield, i, INVALID_TUPLEDESC_IDENTIFIER, PLpgSQL_recfield::nextfield, palloc0(), plpgsql_adddatum(), plpgsql_Datums, PLPGSQL_DTYPE_RECFIELD, pstrdup(), PLpgSQL_recfield::recparentno, and PLpgSQL_recfield::rectupledescid.
Referenced by plpgsql_parse_dblword(), and plpgsql_parse_tripword().
PLpgSQL_rec * plpgsql_build_record | ( | const char * | refname, |
int | lineno, | ||
PLpgSQL_type * | dtype, | ||
Oid | rectypeid, | ||
bool | add2namespace | ||
) |
Definition at line 1801 of file pl_comp.c.
References PLpgSQL_rec::datatype, PLpgSQL_rec::dno, PLpgSQL_rec::dtype, PLpgSQL_rec::erh, PLpgSQL_rec::firstfield, PLpgSQL_rec::lineno, palloc0(), plpgsql_adddatum(), PLPGSQL_DTYPE_REC, plpgsql_ns_additem(), PLPGSQL_NSTYPE_REC, pstrdup(), PLpgSQL_rec::rectypeid, and PLpgSQL_rec::refname.
Referenced by plpgsql_build_variable(), and plpgsql_compile_callback().
PLpgSQL_variable * plpgsql_build_variable | ( | const char * | refname, |
int | lineno, | ||
PLpgSQL_type * | dtype, | ||
bool | add2namespace | ||
) |
Definition at line 1738 of file pl_comp.c.
References PLpgSQL_var::datatype, PLpgSQL_var::dno, PLpgSQL_var::dtype, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), PLpgSQL_var::freeval, PLpgSQL_var::isnull, PLpgSQL_var::lineno, palloc0(), plpgsql_adddatum(), plpgsql_build_record(), PLPGSQL_DTYPE_VAR, plpgsql_ns_additem(), PLPGSQL_NSTYPE_VAR, PLPGSQL_TTYPE_PSEUDO, PLPGSQL_TTYPE_REC, PLPGSQL_TTYPE_SCALAR, pstrdup(), PLpgSQL_var::refname, PLpgSQL_type::ttype, PLpgSQL_type::typoid, and PLpgSQL_var::value.
Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().
PLpgSQL_function * plpgsql_compile | ( | FunctionCallInfo | fcinfo, |
bool | forValidator | ||
) |
Definition at line 106 of file pl_comp.c.
References cached_function_compile(), FunctionCallInfoBaseData::flinfo, FmgrInfo::fn_extra, function, plpgsql_compile_callback(), and plpgsql_delete_callback().
Referenced by plpgsql_call_handler(), and plpgsql_validator().
|
static |
Definition at line 167 of file pl_comp.c.
References add_dummy_return(), add_parameter_name(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), buf, build_datatype(), build_row_from_vars(), CALLED_AS_EVENT_TRIGGER, CALLED_AS_TRIGGER, cfunc_resolve_polymorphic_argtypes(), PLpgSQL_variable::dno, PLpgSQL_row::dno, PLpgSQL_rec::dno, PLpgSQL_variable::dtype, elog, ereport, errcode(), errhint(), errmsg(), ERROR, error_context_stack, FunctionCallInfoBaseData::flinfo, FmgrInfo::fn_expr, FmgrInfo::fn_oid, FunctionCallInfoBaseData::fncollation, format_procedure(), format_type_be(), function, get_fn_expr_rettype(), get_func_arg_info(), GETSTRUCT(), HeapTupleIsValid, i, InvalidOid, MemoryContextSetIdentifier(), MemoryContextSwitchTo(), NameStr, ObjectIdGetDatum(), OidIsValid, palloc(), pfree(), plpgsql_adddatum(), plpgsql_build_datatype(), plpgsql_build_record(), plpgsql_build_variable(), plpgsql_check_syntax, plpgsql_compile_error_callback(), plpgsql_compile_tmp_cxt, plpgsql_curr_compile, PLPGSQL_DML_TRIGGER, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_VAR, plpgsql_DumpExecTree, plpgsql_dumptree(), plpgsql_error_funcname, PLPGSQL_EVENT_TRIGGER, plpgsql_extra_errors, plpgsql_extra_warnings, plpgsql_finish_datums(), PLPGSQL_LABEL_BLOCK, plpgsql_mark_local_assignment_targets(), PLPGSQL_NOT_TRIGGER, plpgsql_ns_init(), plpgsql_ns_push(), PLPGSQL_NSTYPE_REC, PLPGSQL_NSTYPE_VAR, plpgsql_print_strict_params, PLPGSQL_PROMISE_TG_ARGV, PLPGSQL_PROMISE_TG_EVENT, PLPGSQL_PROMISE_TG_LEVEL, PLPGSQL_PROMISE_TG_NAME, PLPGSQL_PROMISE_TG_NARGS, PLPGSQL_PROMISE_TG_OP, PLPGSQL_PROMISE_TG_RELID, PLPGSQL_PROMISE_TG_TABLE_NAME, PLPGSQL_PROMISE_TG_TABLE_SCHEMA, PLPGSQL_PROMISE_TG_TAG, PLPGSQL_PROMISE_TG_WHEN, plpgsql_scanner_finish(), plpgsql_scanner_init(), plpgsql_start_datums(), PLPGSQL_TTYPE_PSEUDO, plpgsql_variable_conflict, plpgsql_yyparse(), ErrorContextCallback::previous, compile_error_callback_arg::proc_source, pstrdup(), ReleaseSysCache(), SearchSysCache1(), snprintf, SysCacheGetAttrNotNull(), TextDatumGetCString, TopMemoryContext, PLpgSQL_type::ttype, type_is_rowtype(), and compile_error_callback_arg::yyscanner.
Referenced by plpgsql_compile().
|
static |
Definition at line 875 of file pl_comp.c.
References arg, errcontext, function_parse_error_transpose(), plpgsql_error_funcname, plpgsql_latest_lineno(), compile_error_callback_arg::proc_source, and compile_error_callback_arg::yyscanner.
Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().
PLpgSQL_function * plpgsql_compile_inline | ( | char * | proc_source | ) |
Definition at line 729 of file pl_comp.c.
References add_dummy_return(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, check_function_bodies, CurrentMemoryContext, PLpgSQL_variable::dno, elog, ERROR, error_context_stack, function, InvalidOid, MemoryContextSwitchTo(), palloc0(), plpgsql_build_datatype(), plpgsql_build_variable(), plpgsql_check_syntax, plpgsql_compile_error_callback(), plpgsql_compile_tmp_cxt, plpgsql_curr_compile, plpgsql_DumpExecTree, plpgsql_dumptree(), plpgsql_error_funcname, plpgsql_finish_datums(), PLPGSQL_LABEL_BLOCK, plpgsql_mark_local_assignment_targets(), PLPGSQL_NOT_TRIGGER, plpgsql_ns_init(), plpgsql_ns_push(), plpgsql_print_strict_params, plpgsql_scanner_finish(), plpgsql_scanner_init(), plpgsql_start_datums(), plpgsql_variable_conflict, plpgsql_yyparse(), ErrorContextCallback::previous, compile_error_callback_arg::proc_source, pstrdup(), and compile_error_callback_arg::yyscanner.
Referenced by plpgsql_inline_handler().
|
static |
Definition at line 2224 of file pl_comp.c.
References function, i, MAXALIGN, palloc(), plpgsql_Datums, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_VAR, and plpgsql_nDatums.
Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().
|
static |
Definition at line 1046 of file pl_comp.c.
References ParamRef::location, make_datum_param(), PLpgSQL_expr::ns, ParamRef::number, ParseState::p_ref_hook_state, plpgsql_ns_lookup(), and snprintf.
Referenced by plpgsql_parser_setup().
PLpgSQL_type * plpgsql_parse_cwordrowtype | ( | List * | idents | ) |
Definition at line 1694 of file pl_comp.c.
References ereport, errcode(), errmsg(), ERROR, get_rel_type_id(), InvalidOid, makeRangeVarFromNameList(), makeTypeNameFromNameList(), MemoryContextSwitchTo(), NoLock, OidIsValid, plpgsql_build_datatype(), plpgsql_compile_tmp_cxt, RangeVarGetRelid, and RangeVar::relname.
PLpgSQL_type * plpgsql_parse_cwordtype | ( | List * | idents | ) |
Definition at line 1545 of file pl_comp.c.
References Assert(), build_datatype(), elog, ereport, errcode(), errmsg(), ERROR, GETSTRUCT(), HeapTupleIsValid, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, linitial, list_copy(), list_delete_last(), list_length(), llast, lsecond, makeRangeVar(), makeRangeVarFromNameList(), MemoryContextSwitchTo(), NoLock, ObjectIdGetDatum(), plpgsql_compile_tmp_cxt, plpgsql_Datums, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, PLPGSQL_NSTYPE_VAR, RangeVarGetRelid, ReleaseSysCache(), RangeVar::relname, SearchSysCache1(), SearchSysCacheAttName(), and strVal.
Definition at line 1339 of file pl_comp.c.
References PLwdatum::datum, PLwdatum::ident, IDENTIFIER_LOOKUP_DECLARE, PLcword::idents, PLwdatum::idents, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, list_make2, makeString(), plpgsql_build_recfield(), plpgsql_Datums, plpgsql_IdentifierLookup, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, PLPGSQL_NSTYPE_VAR, and PLwdatum::quoted.
Referenced by plpgsql_yylex().
PLpgSQL_condition * plpgsql_parse_err_condition | ( | char * | condname | ) |
Definition at line 2143 of file pl_comp.c.
References ereport, errcode(), errmsg(), ERROR, exception_label_map, i, label, ExceptionLabelMap::label, palloc(), PLPGSQL_OTHERS, and ExceptionLabelMap::sqlerrstate.
bool plpgsql_parse_tripword | ( | char * | word1, |
char * | word2, | ||
char * | word3, | ||
PLwdatum * | wdatum, | ||
PLcword * | cword | ||
) |
Definition at line 1420 of file pl_comp.c.
References PLwdatum::datum, PLwdatum::ident, IDENTIFIER_LOOKUP_DECLARE, PLcword::idents, PLwdatum::idents, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, list_make2, list_make3, makeString(), plpgsql_build_recfield(), plpgsql_Datums, plpgsql_IdentifierLookup, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, and PLwdatum::quoted.
Referenced by plpgsql_yylex().
bool plpgsql_parse_word | ( | char * | word1, |
const char * | yytxt, | ||
bool | lookup, | ||
PLwdatum * | wdatum, | ||
PLword * | word | ||
) |
Definition at line 1284 of file pl_comp.c.
References PLwdatum::datum, elog, ERROR, PLwdatum::ident, IDENTIFIER_LOOKUP_NORMAL, PLwdatum::idents, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, NIL, plpgsql_Datums, plpgsql_IdentifierLookup, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, PLPGSQL_NSTYPE_VAR, PLwdatum::quoted, and word().
Referenced by plpgsql_yylex().
PLpgSQL_type * plpgsql_parse_wordrowtype | ( | char * | ident | ) |
Definition at line 1657 of file pl_comp.c.
References ereport, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), ERROR, get_rel_type_id(), ident, InvalidOid, makeTypeName(), OidIsValid, plpgsql_build_datatype(), and RelnameGetRelid().
PLpgSQL_type * plpgsql_parse_wordtype | ( | char * | ident | ) |
Definition at line 1504 of file pl_comp.c.
References ereport, errcode(), errmsg(), ERROR, ident, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, plpgsql_Datums, plpgsql_ns_lookup(), plpgsql_ns_top(), PLPGSQL_NSTYPE_REC, and PLPGSQL_NSTYPE_VAR.
void plpgsql_parser_setup | ( | struct ParseState * | pstate, |
PLpgSQL_expr * | expr | ||
) |
Definition at line 975 of file pl_comp.c.
References ParseState::p_paramref_hook, ParseState::p_post_columnref_hook, ParseState::p_pre_columnref_hook, ParseState::p_ref_hook_state, plpgsql_param_ref(), plpgsql_post_column_ref(), and plpgsql_pre_column_ref().
Referenced by exec_prepare_plan(), and plpgsql_estate_setup().
|
static |
Definition at line 1002 of file pl_comp.c.
References ereport, errcode(), errdetail(), errmsg(), ERROR, ColumnRef::fields, PLpgSQL_expr::func, if(), ColumnRef::location, NameListToString(), ParseState::p_ref_hook_state, parser_errposition(), PLPGSQL_RESOLVE_COLUMN, PLPGSQL_RESOLVE_VARIABLE, resolve_column_ref(), and PLpgSQL_function::resolve_option.
Referenced by plpgsql_parser_setup().
|
static |
Definition at line 988 of file pl_comp.c.
References PLpgSQL_expr::func, if(), ParseState::p_ref_hook_state, PLPGSQL_RESOLVE_VARIABLE, resolve_column_ref(), and PLpgSQL_function::resolve_option.
Referenced by plpgsql_parser_setup().
int plpgsql_recognize_err_condition | ( | const char * | condname, |
bool | allow_sqlstate | ||
) |
Definition at line 2107 of file pl_comp.c.
References ereport, errcode(), errmsg(), ERROR, exception_label_map, i, label, ExceptionLabelMap::label, MAKE_SQLSTATE, and ExceptionLabelMap::sqlerrstate.
Referenced by exec_stmt_raise().
|
static |
Definition at line 2190 of file pl_comp.c.
References datums_alloc, datums_last, MemoryContextAlloc(), plpgsql_compile_tmp_cxt, plpgsql_Datums, and plpgsql_nDatums.
Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().
|
static |
Definition at line 1073 of file pl_comp.c.
References Assert(), PLpgSQL_function::cur_estate, PLpgSQL_execstate::datums, PLpgSQL_recfield::dtype, elog, ereport, errcode(), errmsg(), ERROR, PLpgSQL_recfield::fieldname, ColumnRef::fields, PLpgSQL_rec::firstfield, PLpgSQL_expr::func, i, IsA, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, linitial, list_length(), ColumnRef::location, lsecond, lthird, make_datum_param(), PLpgSQL_recfield::nextfield, PLpgSQL_expr::ns, parser_errposition(), PLPGSQL_DTYPE_RECFIELD, plpgsql_ns_lookup(), PLPGSQL_NSTYPE_REC, PLPGSQL_NSTYPE_VAR, PLpgSQL_recfield::recparentno, strVal, and while().
Referenced by plpgsql_post_column_ref(), and plpgsql_pre_column_ref().
|
static |
Definition at line 41 of file pl_comp.c.
Referenced by plpgsql_adddatum(), and plpgsql_start_datums().
|
static |
Definition at line 44 of file pl_comp.c.
Referenced by plpgsql_add_initdatums(), and plpgsql_start_datums().
|
static |
Definition at line 65 of file pl_comp.c.
Referenced by plpgsql_parse_err_condition(), and plpgsql_recognize_err_condition().
bool plpgsql_check_syntax = false |
Definition at line 48 of file pl_comp.c.
Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().
MemoryContext plpgsql_compile_tmp_cxt |
Definition at line 53 of file pl_comp.c.
Referenced by plpgsql_compile_callback(), plpgsql_compile_inline(), plpgsql_parse_cwordrowtype(), plpgsql_parse_cwordtype(), and plpgsql_start_datums().
PLpgSQL_function* plpgsql_curr_compile |
Definition at line 50 of file pl_comp.c.
Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().
PLpgSQL_datum** plpgsql_Datums |
Definition at line 43 of file pl_comp.c.
Referenced by plpgsql_add_initdatums(), plpgsql_adddatum(), plpgsql_build_recfield(), plpgsql_finish_datums(), plpgsql_parse_cwordtype(), plpgsql_parse_dblword(), plpgsql_parse_tripword(), plpgsql_parse_word(), plpgsql_parse_wordtype(), and plpgsql_start_datums().
bool plpgsql_DumpExecTree = false |
Definition at line 47 of file pl_comp.c.
Referenced by plpgsql_compile_callback(), and plpgsql_compile_inline().
char* plpgsql_error_funcname |
Definition at line 46 of file pl_comp.c.
Referenced by plpgsql_compile_callback(), plpgsql_compile_error_callback(), and plpgsql_compile_inline().
int plpgsql_nDatums |
Definition at line 42 of file pl_comp.c.
Referenced by plpgsql_add_initdatums(), plpgsql_adddatum(), plpgsql_finish_datums(), and plpgsql_start_datums().