diff options
| author | Bruce Momjian | 2005-10-15 02:49:52 +0000 |
|---|---|---|
| committer | Bruce Momjian | 2005-10-15 02:49:52 +0000 |
| commit | 1dc34982511d91ef8a2b71bdcb870f067c1b3da9 (patch) | |
| tree | 1046adab1d4b964e0c38afeec0ee6546f61d9a8a /src/pl/plpgsql | |
| parent | 790c01d28099587bbe2c623d4389b62ee49b1dee (diff) | |
Standard pgindent run for 8.1.
Diffstat (limited to 'src/pl/plpgsql')
| -rw-r--r-- | src/pl/plpgsql/src/pl_comp.c | 268 | ||||
| -rw-r--r-- | src/pl/plpgsql/src/pl_exec.c | 893 | ||||
| -rw-r--r-- | src/pl/plpgsql/src/pl_funcs.c | 134 | ||||
| -rw-r--r-- | src/pl/plpgsql/src/pl_handler.c | 8 | ||||
| -rw-r--r-- | src/pl/plpgsql/src/plpgsql.h | 131 |
5 files changed, 712 insertions, 722 deletions
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c index 1f1d03b8790..2c84899519b 100644 --- a/src/pl/plpgsql/src/pl_comp.c +++ b/src/pl/plpgsql/src/pl_comp.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.93 2005/09/24 22:54:44 tgl Exp $ + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.94 2005/10/15 02:49:49 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -95,7 +95,7 @@ typedef struct plpgsql_hashent { PLpgSQL_func_hashkey key; PLpgSQL_function *function; -} plpgsql_HashEnt; +} plpgsql_HashEnt; #define FUNCS_PER_USER 128 /* initial table size */ @@ -107,7 +107,7 @@ typedef struct { const char *label; int sqlerrstate; -} ExceptionLabelMap; +} ExceptionLabelMap; static const ExceptionLabelMap exception_label_map[] = { #include "plerrcodes.h" @@ -121,27 +121,27 @@ static const ExceptionLabelMap exception_label_map[] = { */ static PLpgSQL_function *do_compile(FunctionCallInfo fcinfo, HeapTuple procTup, - PLpgSQL_func_hashkey *hashkey, + PLpgSQL_func_hashkey * hashkey, bool forValidator); -static int fetchArgInfo(HeapTuple procTup, - Oid **p_argtypes, char ***p_argnames, - char **p_argmodes); +static int fetchArgInfo(HeapTuple procTup, + Oid **p_argtypes, char ***p_argnames, + char **p_argmodes); static PLpgSQL_row *build_row_from_class(Oid classOid); -static PLpgSQL_row *build_row_from_vars(PLpgSQL_variable **vars, int numvars); +static PLpgSQL_row *build_row_from_vars(PLpgSQL_variable ** vars, int numvars); static PLpgSQL_type *build_datatype(HeapTuple typeTup, int32 typmod); static void compute_function_hashkey(FunctionCallInfo fcinfo, Form_pg_proc procStruct, - PLpgSQL_func_hashkey *hashkey, + PLpgSQL_func_hashkey * hashkey, bool forValidator); static void plpgsql_resolve_polymorphic_argtypes(int numargs, Oid *argtypes, char *argmodes, Node *call_expr, bool forValidator, const char *proname); -static PLpgSQL_function *plpgsql_HashTableLookup(PLpgSQL_func_hashkey *func_key); -static void plpgsql_HashTableInsert(PLpgSQL_function *function, - PLpgSQL_func_hashkey *func_key); -static void plpgsql_HashTableDelete(PLpgSQL_function *function); -static void delete_function(PLpgSQL_function *func); +static PLpgSQL_function *plpgsql_HashTableLookup(PLpgSQL_func_hashkey * func_key); +static void plpgsql_HashTableInsert(PLpgSQL_function * function, + PLpgSQL_func_hashkey * func_key); +static void plpgsql_HashTableDelete(PLpgSQL_function * function); +static void delete_function(PLpgSQL_function * func); /* ---------- * plpgsql_compile Make an execution tree for a PL/pgSQL function. @@ -174,8 +174,8 @@ plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator) procStruct = (Form_pg_proc) GETSTRUCT(procTup); /* - * See if there's already a cache entry for the current FmgrInfo. If - * not, try to find one in the hash table. + * See if there's already a cache entry for the current FmgrInfo. If not, + * try to find one in the hash table. */ function = (PLpgSQL_function *) fcinfo->flinfo->fn_extra; @@ -193,7 +193,7 @@ plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator) { /* We have a compiled function, but is it still valid? */ if (!(function->fn_xmin == HeapTupleHeaderGetXmin(procTup->t_data) && - function->fn_cmin == HeapTupleHeaderGetCmin(procTup->t_data))) + function->fn_cmin == HeapTupleHeaderGetCmin(procTup->t_data))) { /* Nope, drop the function and associated storage */ delete_function(function); @@ -202,14 +202,13 @@ plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator) } /* - * If the function wasn't found or was out-of-date, we have to compile - * it + * If the function wasn't found or was out-of-date, we have to compile it */ if (!function) { /* - * Calculate hashkey if we didn't already; we'll need it to store - * the completed function. + * Calculate hashkey if we didn't already; we'll need it to store the + * completed function. */ if (!hashkey_valid) compute_function_hashkey(fcinfo, procStruct, &hashkey, @@ -253,7 +252,7 @@ plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator) static PLpgSQL_function * do_compile(FunctionCallInfo fcinfo, HeapTuple procTup, - PLpgSQL_func_hashkey *hashkey, + PLpgSQL_func_hashkey * hashkey, bool forValidator) { Form_pg_proc procStruct = (Form_pg_proc) GETSTRUCT(procTup); @@ -281,9 +280,9 @@ do_compile(FunctionCallInfo fcinfo, MemoryContext func_cxt; /* - * Setup the scanner input and error info. We assume that this - * function cannot be invoked recursively, so there's no need to save - * and restore the static variables used here. + * Setup the scanner input and error info. We assume that this function + * cannot be invoked recursively, so there's no need to save and restore + * the static variables used here. */ prosrcdatum = SysCacheGetAttr(PROCOID, procTup, Anum_pg_proc_prosrc, &isnull); @@ -317,17 +316,16 @@ do_compile(FunctionCallInfo fcinfo, datums_last = 0; /* - * Do extra syntax checks when validating the function - * definition. We skip this when actually compiling functions for - * execution, for performance reasons. + * Do extra syntax checks when validating the function definition. We skip + * this when actually compiling functions for execution, for performance + * reasons. */ plpgsql_check_syntax = forValidator; /* - * Create the new function node. We allocate the function and all - * of its compile-time storage (e.g. parse tree) in its own memory - * context. This allows us to reclaim the function's storage - * cleanly. + * Create the new function node. We allocate the function and all of its + * compile-time storage (e.g. parse tree) in its own memory context. This + * allows us to reclaim the function's storage cleanly. */ func_cxt = AllocSetContextCreate(TopMemoryContext, "PL/PgSQL function context", @@ -344,18 +342,19 @@ do_compile(FunctionCallInfo fcinfo, function->fn_cmin = HeapTupleHeaderGetCmin(procTup->t_data); function->fn_functype = functype; function->fn_cxt = func_cxt; - function->out_param_varno = -1; /* set up for no OUT param */ + function->out_param_varno = -1; /* set up for no OUT param */ switch (functype) { case T_FUNCTION: + /* - * Fetch info about the procedure's parameters. Allocations - * aren't needed permanently, so make them in tmp cxt. + * Fetch info about the procedure's parameters. Allocations aren't + * needed permanently, so make them in tmp cxt. * - * We also need to resolve any polymorphic input or output - * argument types. In validation mode we won't be able to, - * so we arbitrarily assume we are dealing with integers. + * We also need to resolve any polymorphic input or output argument + * types. In validation mode we won't be able to, so we + * arbitrarily assume we are dealing with integers. */ MemoryContextSwitchTo(compile_tmp_cxt); @@ -396,8 +395,8 @@ do_compile(FunctionCallInfo fcinfo, argdtype->ttype != PLPGSQL_TTYPE_ROW) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("plpgsql functions cannot take type %s", - format_type_be(argtypeid)))); + errmsg("plpgsql functions cannot take type %s", + format_type_be(argtypeid)))); /* Build variable and add to datum list */ argvariable = plpgsql_build_variable(buf, 0, @@ -433,8 +432,8 @@ do_compile(FunctionCallInfo fcinfo, /* * If there's just one OUT parameter, out_param_varno points - * directly to it. If there's more than one, build a row - * that holds all of them. + * directly to it. If there's more than one, build a row that + * holds all of them. */ if (num_out_args == 1) function->out_param_varno = out_arg_variables[0]->dno; @@ -448,14 +447,14 @@ do_compile(FunctionCallInfo fcinfo, } /* - * Check for a polymorphic returntype. If found, use the - * actual returntype type from the caller's FuncExpr node, if - * we have one. (In validation mode we arbitrarily assume we - * are dealing with integers.) + * Check for a polymorphic returntype. If found, use the actual + * returntype type from the caller's FuncExpr node, if we have + * one. (In validation mode we arbitrarily assume we are dealing + * with integers.) * - * Note: errcode is FEATURE_NOT_SUPPORTED because it should - * always work; if it doesn't we're in some context that fails - * to make the info available. + * Note: errcode is FEATURE_NOT_SUPPORTED because it should always + * work; if it doesn't we're in some context that fails to make + * the info available. */ rettypeid = procStruct->prorettype; if (rettypeid == ANYARRAYOID || rettypeid == ANYELEMENTOID) @@ -473,9 +472,9 @@ do_compile(FunctionCallInfo fcinfo, if (!OidIsValid(rettypeid)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("could not determine actual return type " - "for polymorphic function \"%s\"", - plpgsql_error_funcname))); + errmsg("could not determine actual return type " + "for polymorphic function \"%s\"", + plpgsql_error_funcname))); } } @@ -509,8 +508,8 @@ do_compile(FunctionCallInfo fcinfo, else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("plpgsql functions cannot return type %s", - format_type_be(rettypeid)))); + errmsg("plpgsql functions cannot return type %s", + format_type_be(rettypeid)))); } if (typeStruct->typrelid != InvalidOid || @@ -533,7 +532,7 @@ do_compile(FunctionCallInfo fcinfo, num_out_args == 0) { (void) plpgsql_build_variable("$0", 0, - build_datatype(typeTup, -1), + build_datatype(typeTup, -1), true); } } @@ -551,7 +550,7 @@ do_compile(FunctionCallInfo fcinfo, if (procStruct->pronargs != 0) ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), - errmsg("trigger functions cannot have declared arguments"), + errmsg("trigger functions cannot have declared arguments"), errhint("You probably want to use TG_NARGS and TG_ARGV instead."))); /* Add the record for referencing NEW */ @@ -578,43 +577,43 @@ do_compile(FunctionCallInfo fcinfo, /* Add the variable tg_name */ var = plpgsql_build_variable("tg_name", 0, - plpgsql_build_datatype(NAMEOID, -1), + plpgsql_build_datatype(NAMEOID, -1), true); function->tg_name_varno = var->dno; /* Add the variable tg_when */ var = plpgsql_build_variable("tg_when", 0, - plpgsql_build_datatype(TEXTOID, -1), + plpgsql_build_datatype(TEXTOID, -1), true); function->tg_when_varno = var->dno; /* Add the variable tg_level */ var = plpgsql_build_variable("tg_level", 0, - plpgsql_build_datatype(TEXTOID, -1), + plpgsql_build_datatype(TEXTOID, -1), true); function->tg_level_varno = var->dno; /* Add the variable tg_op */ var = plpgsql_build_variable("tg_op", 0, - plpgsql_build_datatype(TEXTOID, -1), + plpgsql_build_datatype(TEXTOID, -1), true); function->tg_op_varno = var->dno; /* Add the variable tg_relid */ var = plpgsql_build_variable("tg_relid", 0, - plpgsql_build_datatype(OIDOID, -1), + plpgsql_build_datatype(OIDOID, -1), true); function->tg_relid_varno = var->dno; /* Add the variable tg_relname */ var = plpgsql_build_variable("tg_relname", 0, - plpgsql_build_datatype(NAMEOID, -1), + plpgsql_build_datatype(NAMEOID, -1), true); function->tg_relname_varno = var->dno; /* Add the variable tg_nargs */ var = plpgsql_build_variable("tg_nargs", 0, - plpgsql_build_datatype(INT4OID, -1), + plpgsql_build_datatype(INT4OID, -1), true); function->tg_nargs_varno = var->dno; @@ -654,11 +653,11 @@ do_compile(FunctionCallInfo fcinfo, /* * If it has OUT parameters or returns VOID or returns a set, we allow - * control to fall off the end without an explicit RETURN statement. - * The easiest way to implement this is to add a RETURN statement to the - * end of the statement list during parsing. However, if the outer block - * has an EXCEPTION clause, we need to make a new outer block, since the - * added RETURN shouldn't act like it is inside the EXCEPTION clause. + * control to fall off the end without an explicit RETURN statement. The + * easiest way to implement this is to add a RETURN statement to the end + * of the statement list during parsing. However, if the outer block has + * an EXCEPTION clause, we need to make a new outer block, since the added + * RETURN shouldn't act like it is inside the EXCEPTION clause. */ if (num_out_args > 0 || function->fn_rettype == VOIDOID || function->fn_retset) @@ -668,8 +667,8 @@ do_compile(FunctionCallInfo fcinfo, PLpgSQL_stmt_block *new; new = palloc0(sizeof(PLpgSQL_stmt_block)); - new->cmd_type = PLPGSQL_STMT_BLOCK; - new->body = list_make1(function->action); + new->cmd_type = PLPGSQL_STMT_BLOCK; + new->body = list_make1(function->action); function->action = new; } @@ -734,15 +733,15 @@ plpgsql_compile_error_callback(void *arg) if (arg) { /* - * Try to convert syntax error position to reference text of - * original CREATE FUNCTION command. + * Try to convert syntax error position to reference text of original + * CREATE FUNCTION command. */ if (function_parse_error_transpose((const char *) arg)) return; /* - * Done if a syntax error position was reported; otherwise we have - * to fall back to a "near line N" report. + * Done if a syntax error position was reported; otherwise we have to + * fall back to a "near line N" report. */ } @@ -784,7 +783,7 @@ fetchArgInfo(HeapTuple procTup, Oid **p_argtypes, char ***p_argnames, * deconstruct_array() since the array data is just going to look like * a C array of values. */ - arr = DatumGetArrayTypeP(proallargtypes); /* ensure not toasted */ + arr = DatumGetArrayTypeP(proallargtypes); /* ensure not toasted */ numargs = ARR_DIMS(arr)[0]; if (ARR_NDIM(arr) != 1 || numargs < 0 || @@ -816,7 +815,7 @@ fetchArgInfo(HeapTuple procTup, Oid **p_argtypes, char ***p_argnames, deconstruct_array(DatumGetArrayTypeP(proargnames), TEXTOID, -1, false, 'i', &elems, &nelems); - if (nelems != numargs) /* should not happen */ + if (nelems != numargs) /* should not happen */ elog(ERROR, "proargnames must have the same number of elements as the function has arguments"); *p_argnames = (char **) palloc(sizeof(char *) * numargs); for (i = 0; i < numargs; i++) @@ -868,7 +867,7 @@ plpgsql_parse_word(char *word) { if (strcmp(cp[0], "tg_argv") == 0) { - bool save_spacescanned = plpgsql_SpaceScanned; + bool save_spacescanned = plpgsql_SpaceScanned; PLpgSQL_trigarg *trigarg; trigarg = palloc0(sizeof(PLpgSQL_trigarg)); @@ -918,8 +917,8 @@ plpgsql_parse_word(char *word) } /* - * Nothing found - up to now it's a word without any special meaning - * for us. + * Nothing found - up to now it's a word without any special meaning for + * us. */ pfree(cp[0]); return T_WORD; @@ -988,8 +987,8 @@ plpgsql_parse_dblword(char *word) case PLPGSQL_NSTYPE_REC: { /* - * First word is a record name, so second word must be a - * field in this record. + * First word is a record name, so second word must be a field + * in this record. */ PLpgSQL_recfield *new; @@ -1010,8 +1009,8 @@ plpgsql_parse_dblword(char *word) case PLPGSQL_NSTYPE_ROW: { /* - * First word is a row name, so second word must be a - * field in this row. + * First word is a row name, so second word must be a field in + * this row. */ PLpgSQL_row *row; int i; @@ -1094,8 +1093,8 @@ plpgsql_parse_tripword(char *word) case PLPGSQL_NSTYPE_REC: { /* - * This word is a record name, so third word must be a - * field in this record. + * This word is a record name, so third word must be a field + * in this record. */ PLpgSQL_recfield *new; @@ -1118,8 +1117,8 @@ plpgsql_parse_tripword(char *word) case PLPGSQL_NSTYPE_ROW: { /* - * This word is a row name, so third word must be a field - * in this row. + * This word is a row name, so third word must be a field in + * this row. */ PLpgSQL_row *row; int i; @@ -1180,8 +1179,8 @@ plpgsql_parse_wordtype(char *word) pfree(cp[1]); /* - * Do a lookup on the compiler's namestack. But ensure it moves up to - * the toplevel. + * Do a lookup on the compiler's namestack. But ensure it moves up to the + * toplevel. */ old_nsstate = plpgsql_ns_setlocal(false); nse = plpgsql_ns_lookup(cp[0], NULL); @@ -1204,8 +1203,8 @@ plpgsql_parse_wordtype(char *word) } /* - * Word wasn't found on the namestack. Try to find a data type with - * that name, but ignore pg_type entries that are in fact class types. + * Word wasn't found on the namestack. Try to find a data type with that + * name, but ignore pg_type entries that are in fact class types. */ typeOid = LookupTypeName(makeTypeName(cp[0])); if (OidIsValid(typeOid)) @@ -1236,8 +1235,8 @@ plpgsql_parse_wordtype(char *word) } /* - * Nothing found - up to now it's a word without any special meaning - * for us. + * Nothing found - up to now it's a word without any special meaning for + * us. */ pfree(cp[0]); return T_ERROR; @@ -1281,8 +1280,8 @@ plpgsql_parse_dblwordtype(char *word) nse = plpgsql_ns_lookup(cp[0], NULL); /* - * If this is a label lookup the second word in that label's - * namestack level + * If this is a label lookup the second word in that label's namestack + * level */ if (nse != NULL) { @@ -1341,8 +1340,8 @@ plpgsql_parse_dblwordtype(char *word) elog(ERROR, "cache lookup failed for type %u", attrStruct->atttypid); /* - * Found that - build a compiler type struct in the caller's cxt - * and return it + * Found that - build a compiler type struct in the caller's cxt and + * return it */ MemoryContextSwitchTo(oldCxt); plpgsql_yylval.dtype = build_datatype(typetup, attrStruct->atttypmod); @@ -1383,7 +1382,7 @@ plpgsql_parse_tripwordtype(char *word) int i; RangeVar *relvar; MemoryContext oldCxt; - int result = T_ERROR; + int result = T_ERROR; /* Avoid memory leaks in the long-term function context */ oldCxt = MemoryContextSwitchTo(compile_tmp_cxt); @@ -1410,7 +1409,7 @@ plpgsql_parse_tripwordtype(char *word) cp[1][qualified_att_len - i - 1] = '\0'; relvar = makeRangeVarFromNameList(stringToQualifiedNameList(cp[0], - "plpgsql_parse_tripwordtype")); + "plpgsql_parse_tripwordtype")); classOid = RangeVarGetRelid(relvar, true); if (!OidIsValid(classOid)) goto done; @@ -1447,8 +1446,8 @@ plpgsql_parse_tripwordtype(char *word) elog(ERROR, "cache lookup failed for type %u", attrStruct->atttypid); /* - * Found that - build a compiler type struct in the caller's cxt - * and return it + * Found that - build a compiler type struct in the caller's cxt and + * return it */ MemoryContextSwitchTo(oldCxt); plpgsql_yylval.dtype = build_datatype(typetup, attrStruct->atttypmod); @@ -1555,11 +1554,11 @@ plpgsql_parse_dblwordrowtype(char *word) * * The returned struct may be a PLpgSQL_var, PLpgSQL_row, or * PLpgSQL_rec depending on the given datatype, and is allocated via - * palloc. The struct is automatically added to the current datum + * palloc. The struct is automatically added to the current datum * array, and optionally to the current namespace. */ PLpgSQL_variable * -plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype, +plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type * dtype, bool add2namespace) { PLpgSQL_variable *result; @@ -1613,8 +1612,7 @@ plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype, case PLPGSQL_TTYPE_REC: { /* - * "record" type -- build a variable-contents record - * variable + * "record" type -- build a variable-contents record variable */ PLpgSQL_rec *rec; @@ -1636,7 +1634,7 @@ plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("variable \"%s\" has pseudo-type %s", refname, format_type_be(dtype->typoid)))); - result = NULL; /* keep compiler quiet */ + result = NULL; /* keep compiler quiet */ break; default: elog(ERROR, "unrecognized ttype: %d", dtype->ttype); @@ -1676,8 +1674,8 @@ build_row_from_class(Oid classOid) errmsg("relation \"%s\" is not a table", relname))); /* - * Create a row datum entry and all the required variables that it - * will point to. + * Create a row datum entry and all the required variables that it will + * point to. */ row = palloc0(sizeof(PLpgSQL_row)); row->dtype = PLPGSQL_DTYPE_ROW; @@ -1707,16 +1705,16 @@ build_row_from_class(Oid classOid) /* * Create the internal variable for the field * - * We know if the table definitions contain a default value or if - * the field is declared in the table as NOT NULL. But it's - * possible to create a table field as NOT NULL without a - * default value and that would lead to problems later when - * initializing the variables due to entering a block at - * execution time. Thus we ignore this information for now. + * We know if the table definitions contain a default value or if the + * field is declared in the table as NOT NULL. But it's possible + * to create a table field as NOT NULL without a default value and + * that would lead to problems later when initializing the + * variables due to entering a block at execution time. Thus we + * ignore this information for now. */ var = plpgsql_build_variable(refname, 0, - plpgsql_build_datatype(attrStruct->atttypid, - attrStruct->atttypmod), + plpgsql_build_datatype(attrStruct->atttypid, + attrStruct->atttypmod), false); /* Add the variable to the row */ @@ -1740,7 +1738,7 @@ build_row_from_class(Oid classOid) * Build a row-variable data structure given the component variables. */ static PLpgSQL_row * -build_row_from_vars(PLpgSQL_variable **vars, int numvars) +build_row_from_vars(PLpgSQL_variable ** vars, int numvars) { PLpgSQL_row *row; int i; @@ -1755,8 +1753,8 @@ build_row_from_vars(PLpgSQL_variable **vars, int numvars) for (i = 0; i < numvars; i++) { PLpgSQL_variable *var = vars[i]; - Oid typoid = RECORDOID; - int32 typmod = -1; + Oid typoid = RECORDOID; + int32 typmod = -1; switch (var->dtype) { @@ -1783,7 +1781,7 @@ build_row_from_vars(PLpgSQL_variable **vars, int numvars) row->fieldnames[i] = var->refname; row->varnos[i] = var->dno; - TupleDescInitEntry(row->rowtupdesc, i+1, + TupleDescInitEntry(row->rowtupdesc, i + 1, var->refname, typoid, typmod, 0); @@ -1899,8 +1897,8 @@ plpgsql_parse_err_condition(char *condname) PLpgSQL_condition *prev; /* - * XXX Eventually we will want to look for user-defined exception - * names here. + * XXX Eventually we will want to look for user-defined exception names + * here. */ /* @@ -1944,7 +1942,7 @@ plpgsql_parse_err_condition(char *condname) * ---------- */ void -plpgsql_adddatum(PLpgSQL_datum *new) +plpgsql_adddatum(PLpgSQL_datum * new) { if (plpgsql_nDatums == datums_alloc) { @@ -2020,7 +2018,7 @@ plpgsql_add_initdatums(int **varnos) static void compute_function_hashkey(FunctionCallInfo fcinfo, Form_pg_proc procStruct, - PLpgSQL_func_hashkey *hashkey, + PLpgSQL_func_hashkey * hashkey, bool forValidator) { /* Make sure any unused bytes of the struct are zero */ @@ -2030,9 +2028,9 @@ compute_function_hashkey(FunctionCallInfo fcinfo, hashkey->funcOid = fcinfo->flinfo->fn_oid; /* - * if trigger, get relation OID. In validation mode we do not know - * what relation is intended to be used, so we leave trigrelOid zero; - * the hash entry built in this case will never really be used. + * if trigger, get relation OID. In validation mode we do not know what + * relation is intended to be used, so we leave trigrelOid zero; the hash + * entry built in this case will never really be used. */ if (CALLED_AS_TRIGGER(fcinfo) && !forValidator) { @@ -2103,7 +2101,7 @@ plpgsql_resolve_polymorphic_argtypes(int numargs, } static void -delete_function(PLpgSQL_function *func) +delete_function(PLpgSQL_function * func) { /* remove function from hash table */ plpgsql_HashTableDelete(func); @@ -2112,8 +2110,8 @@ delete_function(PLpgSQL_function *func) MemoryContextDelete(func->fn_cxt); /* - * Caller should be sure not to use passed-in pointer, as it now - * points to pfree'd storage + * Caller should be sure not to use passed-in pointer, as it now points to + * pfree'd storage */ } @@ -2137,7 +2135,7 @@ plpgsql_HashTableInit(void) } static PLpgSQL_function * -plpgsql_HashTableLookup(PLpgSQL_func_hashkey *func_key) +plpgsql_HashTableLookup(PLpgSQL_func_hashkey * func_key) { plpgsql_HashEnt *hentry; @@ -2152,8 +2150,8 @@ plpgsql_HashTableLookup(PLpgSQL_func_hashkey *func_key) } static void -plpgsql_HashTableInsert(PLpgSQL_function *function, - PLpgSQL_func_hashkey *func_key) +plpgsql_HashTableInsert(PLpgSQL_function * function, + PLpgSQL_func_hashkey * func_key) { plpgsql_HashEnt *hentry; bool found; @@ -2171,12 +2169,12 @@ plpgsql_HashTableInsert(PLpgSQL_function *function, } static void -plpgsql_HashTableDelete(PLpgSQL_function *function) +plpgsql_HashTableDelete(PLpgSQL_function * function) { plpgsql_HashEnt *hentry; hentry = (plpgsql_HashEnt *) hash_search(plpgsql_HashTable, - (void *) function->fn_hashkey, + (void *) function->fn_hashkey, HASH_REMOVE, NULL); if (hentry == NULL) diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index 6238aef0eba..721b1014fdc 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.152 2005/09/13 16:16:17 tgl Exp $ + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.153 2005/10/15 02:49:49 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -75,97 +75,97 @@ static PLpgSQL_expr *active_simple_exprs = NULL; * Local function forward declarations ************************************************************/ static void plpgsql_exec_error_callback(void *arg); -static PLpgSQL_datum *copy_plpgsql_datum(PLpgSQL_datum *datum); - -static int exec_stmt_block(PLpgSQL_execstate *estate, - PLpgSQL_stmt_block *block); -static int exec_stmts(PLpgSQL_execstate *estate, - List *stmts); -static int exec_stmt(PLpgSQL_execstate *estate, - PLpgSQL_stmt *stmt); -static int exec_stmt_assign(PLpgSQL_execstate *estate, - PLpgSQL_stmt_assign *stmt); -static int exec_stmt_perform(PLpgSQL_execstate *estate, - PLpgSQL_stmt_perform *stmt); -static int exec_stmt_getdiag(PLpgSQL_execstate *estate, - PLpgSQL_stmt_getdiag *stmt); -static int exec_stmt_if(PLpgSQL_execstate *estate, - PLpgSQL_stmt_if *stmt); -static int exec_stmt_loop(PLpgSQL_execstate *estate, - PLpgSQL_stmt_loop *stmt); -static int exec_stmt_while(PLpgSQL_execstate *estate, - PLpgSQL_stmt_while *stmt); -static int exec_stmt_fori(PLpgSQL_execstate *estate, - PLpgSQL_stmt_fori *stmt); -static int exec_stmt_fors(PLpgSQL_execstate *estate, - PLpgSQL_stmt_fors *stmt); -static int exec_stmt_select(PLpgSQL_execstate *estate, - PLpgSQL_stmt_select *stmt); -static int exec_stmt_open(PLpgSQL_execstate *estate, - PLpgSQL_stmt_open *stmt); -static int exec_stmt_fetch(PLpgSQL_execstate *estate, - PLpgSQL_stmt_fetch *stmt); -static int exec_stmt_close(PLpgSQL_execstate *estate, - PLpgSQL_stmt_close *stmt); -static int exec_stmt_exit(PLpgSQL_execstate *estate, - PLpgSQL_stmt_exit *stmt); -static int exec_stmt_return(PLpgSQL_execstate *estate, - PLpgSQL_stmt_return *stmt); -static int exec_stmt_return_next(PLpgSQL_execstate *estate, - PLpgSQL_stmt_return_next *stmt); -static int exec_stmt_raise(PLpgSQL_execstate *estate, - PLpgSQL_stmt_raise *stmt); -static int exec_stmt_execsql(PLpgSQL_execstate *estate, - PLpgSQL_stmt_execsql *stmt); -static int exec_stmt_dynexecute(PLpgSQL_execstate *estate, - PLpgSQL_stmt_dynexecute *stmt); -static int exec_stmt_dynfors(PLpgSQL_execstate *estate, - PLpgSQL_stmt_dynfors *stmt); - -static void plpgsql_estate_setup(PLpgSQL_execstate *estate, - PLpgSQL_function *func, +static PLpgSQL_datum *copy_plpgsql_datum(PLpgSQL_datum * datum); + +static int exec_stmt_block(PLpgSQL_execstate * estate, + PLpgSQL_stmt_block * block); +static int exec_stmts(PLpgSQL_execstate * estate, + List *stmts); +static int exec_stmt(PLpgSQL_execstate * estate, + PLpgSQL_stmt * stmt); +static int exec_stmt_assign(PLpgSQL_execstate * estate, + PLpgSQL_stmt_assign * stmt); +static int exec_stmt_perform(PLpgSQL_execstate * estate, + PLpgSQL_stmt_perform * stmt); +static int exec_stmt_getdiag(PLpgSQL_execstate * estate, + PLpgSQL_stmt_getdiag * stmt); +static int exec_stmt_if(PLpgSQL_execstate * estate, + PLpgSQL_stmt_if * stmt); +static int exec_stmt_loop(PLpgSQL_execstate * estate, + PLpgSQL_stmt_loop * stmt); +static int exec_stmt_while(PLpgSQL_execstate * estate, + PLpgSQL_stmt_while * stmt); +static int exec_stmt_fori(PLpgSQL_execstate * estate, + PLpgSQL_stmt_fori * stmt); +static int exec_stmt_fors(PLpgSQL_execstate * estate, + PLpgSQL_stmt_fors * stmt); +static int exec_stmt_select(PLpgSQL_execstate * estate, + PLpgSQL_stmt_select * stmt); +static int exec_stmt_open(PLpgSQL_execstate * estate, + PLpgSQL_stmt_open * stmt); +static int exec_stmt_fetch(PLpgSQL_execstate * estate, + PLpgSQL_stmt_fetch * stmt); +static int exec_stmt_close(PLpgSQL_execstate * estate, + PLpgSQL_stmt_close * stmt); +static int exec_stmt_exit(PLpgSQL_execstate * estate, + PLpgSQL_stmt_exit * stmt); +static int exec_stmt_return(PLpgSQL_execstate * estate, + PLpgSQL_stmt_return * stmt); +static int exec_stmt_return_next(PLpgSQL_execstate * estate, + PLpgSQL_stmt_return_next * stmt); +static int exec_stmt_raise(PLpgSQL_execstate * estate, + PLpgSQL_stmt_raise * stmt); +static int exec_stmt_execsql(PLpgSQL_execstate * estate, + PLpgSQL_stmt_execsql * stmt); +static int exec_stmt_dynexecute(PLpgSQL_execstate * estate, + PLpgSQL_stmt_dynexecute * stmt); +static int exec_stmt_dynfors(PLpgSQL_execstate * estate, + PLpgSQL_stmt_dynfors * stmt); + +static void plpgsql_estate_setup(PLpgSQL_execstate * estate, + PLpgSQL_function * func, ReturnSetInfo *rsi); -static void exec_eval_cleanup(PLpgSQL_execstate *estate); +static void exec_eval_cleanup(PLpgSQL_execstate * estate); -static void exec_prepare_plan(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr); +static void exec_prepare_plan(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr); static bool exec_simple_check_node(Node *node); -static void exec_simple_check_plan(PLpgSQL_expr *expr); -static Datum exec_eval_simple_expr(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, +static void exec_simple_check_plan(PLpgSQL_expr * expr); +static Datum exec_eval_simple_expr(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, bool *isNull, Oid *rettype); -static void exec_assign_expr(PLpgSQL_execstate *estate, - PLpgSQL_datum *target, - PLpgSQL_expr *expr); -static void exec_assign_value(PLpgSQL_execstate *estate, - PLpgSQL_datum *target, +static void exec_assign_expr(PLpgSQL_execstate * estate, + PLpgSQL_datum * target, + PLpgSQL_expr * expr); +static void exec_assign_value(PLpgSQL_execstate * estate, + PLpgSQL_datum * target, Datum value, Oid valtype, bool *isNull); -static void exec_eval_datum(PLpgSQL_execstate *estate, - PLpgSQL_datum *datum, +static void exec_eval_datum(PLpgSQL_execstate * estate, + PLpgSQL_datum * datum, Oid expectedtypeid, Oid *typeid, Datum *value, bool *isnull); -static int exec_eval_integer(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, +static int exec_eval_integer(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, bool *isNull); -static bool exec_eval_boolean(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, +static bool exec_eval_boolean(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, bool *isNull); -static Datum exec_eval_expr(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, +static Datum exec_eval_expr(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, bool *isNull, Oid *rettype); -static int exec_run_select(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, long maxtuples, Portal *portalP); -static void exec_move_row(PLpgSQL_execstate *estate, - PLpgSQL_rec *rec, - PLpgSQL_row *row, +static int exec_run_select(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, long maxtuples, Portal *portalP); +static void exec_move_row(PLpgSQL_execstate * estate, + PLpgSQL_rec * rec, + PLpgSQL_row * row, HeapTuple tup, TupleDesc tupdesc); -static HeapTuple make_tuple_from_row(PLpgSQL_execstate *estate, - PLpgSQL_row *row, +static HeapTuple make_tuple_from_row(PLpgSQL_execstate * estate, + PLpgSQL_row * row, TupleDesc tupdesc); static char *convert_value_to_string(Datum value, Oid valtype); static Datum exec_cast_value(Datum value, Oid valtype, @@ -177,10 +177,10 @@ static Datum exec_cast_value(Datum value, Oid valtype, static Datum exec_simple_cast_value(Datum value, Oid valtype, Oid reqtype, int32 reqtypmod, bool isnull); -static void exec_init_tuple_store(PLpgSQL_execstate *estate); +static void exec_init_tuple_store(PLpgSQL_execstate * estate); static bool compatible_tupdesc(TupleDesc td1, TupleDesc td2); -static void exec_set_found(PLpgSQL_execstate *estate, bool state); -static void free_var(PLpgSQL_var *var); +static void exec_set_found(PLpgSQL_execstate * estate, bool state); +static void free_var(PLpgSQL_var * var); /* ---------- @@ -189,7 +189,7 @@ static void free_var(PLpgSQL_var *var); * ---------- */ Datum -plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo) +plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) { PLpgSQL_execstate estate; ErrorContextCallback plerrcontext; @@ -290,8 +290,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo) estate.err_text = NULL; /* - * Provide a more helpful message if a CONTINUE has been used - * outside a loop. + * Provide a more helpful message if a CONTINUE has been used outside + * a loop. */ if (rc == PLPGSQL_RC_CONTINUE) ereport(ERROR, @@ -299,8 +299,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo) errmsg("CONTINUE cannot be used outside a loop"))); else ereport(ERROR, - (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT), - errmsg("control reached end of function without RETURN"))); + (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT), + errmsg("control reached end of function without RETURN"))); } /* @@ -399,7 +399,7 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo) * ---------- */ HeapTuple -plpgsql_exec_trigger(PLpgSQL_function *func, +plpgsql_exec_trigger(PLpgSQL_function * func, TriggerData *trigdata) { PLpgSQL_execstate estate; @@ -493,7 +493,7 @@ plpgsql_exec_trigger(PLpgSQL_function *func, var = (PLpgSQL_var *) (estate.datums[func->tg_name_varno]); var->value = DirectFunctionCall1(namein, - CStringGetDatum(trigdata->tg_trigger->tgname)); + CStringGetDatum(trigdata->tg_trigger->tgname)); var->isnull = false; var->freeval = true; @@ -524,7 +524,7 @@ plpgsql_exec_trigger(PLpgSQL_function *func, var = (PLpgSQL_var *) (estate.datums[func->tg_relname_varno]); var->value = DirectFunctionCall1(namein, - CStringGetDatum(RelationGetRelationName(trigdata->tg_relation))); + CStringGetDatum(RelationGetRelationName(trigdata->tg_relation))); var->isnull = false; var->freeval = true; @@ -534,8 +534,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func, var->freeval = false; /* - * Store the trigger argument values into the special execution - * state variables + * Store the trigger argument values into the special execution state + * variables */ estate.err_text = gettext_noop("while storing call arguments into local variables"); estate.trig_nargs = trigdata->tg_trigger->tgnargs; @@ -546,7 +546,7 @@ plpgsql_exec_trigger(PLpgSQL_function *func, estate.trig_argv = palloc(sizeof(Datum) * estate.trig_nargs); for (i = 0; i < trigdata->tg_trigger->tgnargs; i++) estate.trig_argv[i] = DirectFunctionCall1(textin, - CStringGetDatum(trigdata->tg_trigger->tgargs[i])); + CStringGetDatum(trigdata->tg_trigger->tgargs[i])); } /* @@ -566,8 +566,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func, estate.err_text = NULL; /* - * Provide a more helpful message if a CONTINUE has been used - * outside a loop. + * Provide a more helpful message if a CONTINUE has been used outside + * a loop. */ if (rc == PLPGSQL_RC_CONTINUE) ereport(ERROR, @@ -575,8 +575,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func, errmsg("CONTINUE cannot be used outside a loop"))); else ereport(ERROR, - (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT), - errmsg("control reached end of trigger procedure without RETURN"))); + (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT), + errmsg("control reached end of trigger procedure without RETURN"))); } if (estate.retisset) @@ -585,14 +585,14 @@ plpgsql_exec_trigger(PLpgSQL_function *func, errmsg("trigger procedure cannot return a set"))); /* - * Check that the returned tuple structure has the same attributes, - * the relation that fired the trigger has. A per-statement trigger - * always needs to return NULL, so we ignore any return value the - * function itself produces (XXX: is this a good idea?) + * Check that the returned tuple structure has the same attributes, the + * relation that fired the trigger has. A per-statement trigger always + * needs to return NULL, so we ignore any return value the function itself + * produces (XXX: is this a good idea?) * * XXX This way it is possible, that the trigger returns a tuple where - * attributes don't have the correct atttypmod's length. It's up to - * the trigger's programmer to ensure that this doesn't happen. Jan + * attributes don't have the correct atttypmod's length. It's up to the + * trigger's programmer to ensure that this doesn't happen. Jan */ if (estate.retisnull || TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event)) rettup = NULL; @@ -652,10 +652,10 @@ plpgsql_exec_error_callback(void *arg) else if (estate->err_text != NULL) { /* - * We don't expend the cycles to run gettext() on err_text unless - * we actually need it. Therefore, places that set up err_text - * should use gettext_noop() to ensure the strings get recorded in - * the message dictionary. + * We don't expend the cycles to run gettext() on err_text unless we + * actually need it. Therefore, places that set up err_text should + * use gettext_noop() to ensure the strings get recorded in the + * message dictionary. */ /* @@ -677,48 +677,49 @@ plpgsql_exec_error_callback(void *arg) * ---------- */ static PLpgSQL_datum * -copy_plpgsql_datum(PLpgSQL_datum *datum) +copy_plpgsql_datum(PLpgSQL_datum * datum) { PLpgSQL_datum *result; switch (datum->dtype) { case PLPGSQL_DTYPE_VAR: - { - PLpgSQL_var *new = palloc(sizeof(PLpgSQL_var)); + { + PLpgSQL_var *new = palloc(sizeof(PLpgSQL_var)); - memcpy(new, datum, sizeof(PLpgSQL_var)); - /* Ensure the value is null (possibly not needed?) */ - new->value = 0; - new->isnull = true; - new->freeval = false; + memcpy(new, datum, sizeof(PLpgSQL_var)); + /* Ensure the value is null (possibly not needed?) */ + new->value = 0; + new->isnull = true; + new->freeval = false; - result = (PLpgSQL_datum *) new; - } - break; + result = (PLpgSQL_datum *) new; + } + break; case PLPGSQL_DTYPE_REC: - { - PLpgSQL_rec *new = palloc(sizeof(PLpgSQL_rec)); + { + PLpgSQL_rec *new = palloc(sizeof(PLpgSQL_rec)); - memcpy(new, datum, sizeof(PLpgSQL_rec)); - /* Ensure the value is null (possibly not needed?) */ - new->tup = NULL; - new->tupdesc = NULL; - new->freetup = false; - new->freetupdesc = false; + memcpy(new, datum, sizeof(PLpgSQL_rec)); + /* Ensure the value is null (possibly not needed?) */ + new->tup = NULL; + new->tupdesc = NULL; + new->freetup = false; + new->freetupdesc = false; - result = (PLpgSQL_datum *) new; - } - break; + result = (PLpgSQL_datum *) new; + } + break; case PLPGSQL_DTYPE_ROW: case PLPGSQL_DTYPE_RECFIELD: case PLPGSQL_DTYPE_ARRAYELEM: case PLPGSQL_DTYPE_TRIGARG: + /* - * These datum records are read-only at runtime, so no need - * to copy them + * These datum records are read-only at runtime, so no need to + * copy them */ result = datum; break; @@ -734,7 +735,7 @@ copy_plpgsql_datum(PLpgSQL_datum *datum) static bool -exception_matches_conditions(ErrorData *edata, PLpgSQL_condition *cond) +exception_matches_conditions(ErrorData *edata, PLpgSQL_condition * cond) { for (; cond != NULL; cond = cond->next) { @@ -766,7 +767,7 @@ exception_matches_conditions(ErrorData *edata, PLpgSQL_condition *cond) * ---------- */ static int -exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block) +exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block) { volatile int rc = -1; int i; @@ -794,9 +795,9 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block) var->isnull = true; if (var->notnull) ereport(ERROR, - (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), - errmsg("variable \"%s\" declared NOT NULL cannot default to NULL", - var->refname))); + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("variable \"%s\" declared NOT NULL cannot default to NULL", + var->refname))); } else { @@ -836,8 +837,7 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block) if (block->exceptions) { /* - * Execute the statements in the block's body inside a - * sub-transaction + * Execute the statements in the block's body inside a sub-transaction */ MemoryContext oldcontext = CurrentMemoryContext; ResourceOwner oldowner = CurrentResourceOwner; @@ -856,15 +856,15 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block) CurrentResourceOwner = oldowner; /* - * AtEOSubXact_SPI() should not have popped any SPI context, - * but just in case it did, make sure we remain connected. + * AtEOSubXact_SPI() should not have popped any SPI context, but + * just in case it did, make sure we remain connected. */ SPI_restore_connection(); } PG_CATCH(); { - ErrorData *edata; - ListCell *e; + ErrorData *edata; + ListCell *e; /* Save error info */ MemoryContextSwitchTo(oldcontext); @@ -877,24 +877,23 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block) CurrentResourceOwner = oldowner; /* - * If AtEOSubXact_SPI() popped any SPI context of the subxact, - * it will have left us in a disconnected state. We need this - * hack to return to connected state. + * If AtEOSubXact_SPI() popped any SPI context of the subxact, it + * will have left us in a disconnected state. We need this hack + * to return to connected state. */ SPI_restore_connection(); /* Look for a matching exception handler */ - foreach (e, block->exceptions->exc_list) + foreach(e, block->exceptions->exc_list) { PLpgSQL_exception *exception = (PLpgSQL_exception *) lfirst(e); if (exception_matches_conditions(edata, exception->conditions)) { /* - * Initialize the magic SQLSTATE and SQLERRM - * variables for the exception block. We needn't - * do this until we have found a matching - * exception. + * Initialize the magic SQLSTATE and SQLERRM variables for + * the exception block. We needn't do this until we have + * found a matching exception. */ PLpgSQL_var *state_var; PLpgSQL_var *errm_var; @@ -902,14 +901,14 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block) state_var = (PLpgSQL_var *) estate->datums[block->exceptions->sqlstate_varno]; state_var->value = DirectFunctionCall1(textin, - CStringGetDatum(unpack_sql_state(edata->sqlerrcode))); + CStringGetDatum(unpack_sql_state(edata->sqlerrcode))); state_var->freeval = true; state_var->isnull = false; errm_var = (PLpgSQL_var *) estate->datums[block->exceptions->sqlerrm_varno]; errm_var->value = DirectFunctionCall1(textin, - CStringGetDatum(edata->message)); + CStringGetDatum(edata->message)); errm_var->freeval = true; errm_var->isnull = false; @@ -956,7 +955,7 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block) return PLPGSQL_RC_EXIT; estate->exitlabel = NULL; return PLPGSQL_RC_OK; - + default: elog(ERROR, "unrecognized rc: %d", rc); } @@ -971,14 +970,15 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block) * ---------- */ static int -exec_stmts(PLpgSQL_execstate *estate, List *stmts) +exec_stmts(PLpgSQL_execstate * estate, List *stmts) { ListCell *s; - foreach (s, stmts) + foreach(s, stmts) { PLpgSQL_stmt *stmt = (PLpgSQL_stmt *) lfirst(s); - int rc = exec_stmt(estate, stmt); + int rc = exec_stmt(estate, stmt); + if (rc != PLPGSQL_RC_OK) return rc; } @@ -993,7 +993,7 @@ exec_stmts(PLpgSQL_execstate *estate, List *stmts) * ---------- */ static int -exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt) +exec_stmt(PLpgSQL_execstate * estate, PLpgSQL_stmt * stmt) { PLpgSQL_stmt *save_estmt; int rc = -1; @@ -1102,7 +1102,7 @@ exec_stmt(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt) * ---------- */ static int -exec_stmt_assign(PLpgSQL_execstate *estate, PLpgSQL_stmt_assign *stmt) +exec_stmt_assign(PLpgSQL_execstate * estate, PLpgSQL_stmt_assign * stmt) { Assert(stmt->varno >= 0); @@ -1118,7 +1118,7 @@ exec_stmt_assign(PLpgSQL_execstate *estate, PLpgSQL_stmt_assign *stmt) * ---------- */ static int -exec_stmt_perform(PLpgSQL_execstate *estate, PLpgSQL_stmt_perform *stmt) +exec_stmt_perform(PLpgSQL_execstate * estate, PLpgSQL_stmt_perform * stmt) { PLpgSQL_expr *expr = stmt->expr; @@ -1135,15 +1135,15 @@ exec_stmt_perform(PLpgSQL_execstate *estate, PLpgSQL_stmt_perform *stmt) * ---------- */ static int -exec_stmt_getdiag(PLpgSQL_execstate *estate, PLpgSQL_stmt_getdiag *stmt) +exec_stmt_getdiag(PLpgSQL_execstate * estate, PLpgSQL_stmt_getdiag * stmt) { - ListCell *lc; + ListCell *lc; - foreach (lc, stmt->diag_items) + foreach(lc, stmt->diag_items) { - PLpgSQL_diag_item *diag_item = (PLpgSQL_diag_item *) lfirst(lc); - PLpgSQL_datum *var; - bool isnull = false; + PLpgSQL_diag_item *diag_item = (PLpgSQL_diag_item *) lfirst(lc); + PLpgSQL_datum *var; + bool isnull = false; if (diag_item->target <= 0) continue; @@ -1185,7 +1185,7 @@ exec_stmt_getdiag(PLpgSQL_execstate *estate, PLpgSQL_stmt_getdiag *stmt) * ---------- */ static int -exec_stmt_if(PLpgSQL_execstate *estate, PLpgSQL_stmt_if *stmt) +exec_stmt_if(PLpgSQL_execstate * estate, PLpgSQL_stmt_if * stmt) { bool value; bool isnull; @@ -1214,11 +1214,11 @@ exec_stmt_if(PLpgSQL_execstate *estate, PLpgSQL_stmt_if *stmt) * ---------- */ static int -exec_stmt_loop(PLpgSQL_execstate *estate, PLpgSQL_stmt_loop *stmt) +exec_stmt_loop(PLpgSQL_execstate * estate, PLpgSQL_stmt_loop * stmt) { for (;;) { - int rc = exec_stmts(estate, stmt->body); + int rc = exec_stmts(estate, stmt->body); switch (rc) { @@ -1234,7 +1234,7 @@ exec_stmt_loop(PLpgSQL_execstate *estate, PLpgSQL_stmt_loop *stmt) return PLPGSQL_RC_EXIT; estate->exitlabel = NULL; return PLPGSQL_RC_OK; - + case PLPGSQL_RC_CONTINUE: if (estate->exitlabel == NULL) /* anonymous continue, so re-run the loop */ @@ -1267,7 +1267,7 @@ exec_stmt_loop(PLpgSQL_execstate *estate, PLpgSQL_stmt_loop *stmt) * ---------- */ static int -exec_stmt_while(PLpgSQL_execstate *estate, PLpgSQL_stmt_while *stmt) +exec_stmt_while(PLpgSQL_execstate * estate, PLpgSQL_stmt_while * stmt) { for (;;) { @@ -1330,7 +1330,7 @@ exec_stmt_while(PLpgSQL_execstate *estate, PLpgSQL_stmt_while *stmt) * ---------- */ static int -exec_stmt_fori(PLpgSQL_execstate *estate, PLpgSQL_stmt_fori *stmt) +exec_stmt_fori(PLpgSQL_execstate * estate, PLpgSQL_stmt_fori * stmt) { PLpgSQL_var *var; Datum value; @@ -1413,9 +1413,9 @@ exec_stmt_fori(PLpgSQL_execstate *estate, PLpgSQL_stmt_fori *stmt) } /* - * otherwise, this is a labelled exit that does not match - * the current statement's label, if any: return RC_EXIT - * so that the EXIT continues to propagate up the stack. + * otherwise, this is a labelled exit that does not match the + * current statement's label, if any: return RC_EXIT so that the + * EXIT continues to propagate up the stack. */ break; @@ -1435,12 +1435,11 @@ exec_stmt_fori(PLpgSQL_execstate *estate, PLpgSQL_stmt_fori *stmt) else { /* - * otherwise, this is a named continue that does not - * match the current statement's label, if any: return - * RC_CONTINUE so that the CONTINUE will propagate up - * the stack. + * otherwise, this is a named continue that does not match the + * current statement's label, if any: return RC_CONTINUE so + * that the CONTINUE will propagate up the stack. */ - break; + break; } } @@ -1455,9 +1454,9 @@ exec_stmt_fori(PLpgSQL_execstate *estate, PLpgSQL_stmt_fori *stmt) /* * Set the FOUND variable to indicate the result of executing the loop - * (namely, whether we looped one or more times). This must be set - * here so that it does not interfere with the value of the FOUND - * variable inside the loop processing itself. + * (namely, whether we looped one or more times). This must be set here so + * that it does not interfere with the value of the FOUND variable inside + * the loop processing itself. */ exec_set_found(estate, found); @@ -1473,7 +1472,7 @@ exec_stmt_fori(PLpgSQL_execstate *estate, PLpgSQL_stmt_fori *stmt) * ---------- */ static int -exec_stmt_fors(PLpgSQL_execstate *estate, PLpgSQL_stmt_fors *stmt) +exec_stmt_fors(PLpgSQL_execstate * estate, PLpgSQL_stmt_fors * stmt) { PLpgSQL_rec *rec = NULL; PLpgSQL_row *row = NULL; @@ -1505,8 +1504,8 @@ exec_stmt_fors(PLpgSQL_execstate *estate, PLpgSQL_stmt_fors *stmt) n = SPI_processed; /* - * If the query didn't return any rows, set the target to NULL and - * return with FOUND = false. + * If the query didn't return any rows, set the target to NULL and return + * with FOUND = false. */ if (n == 0) exec_move_row(estate, rec, row, NULL, tuptab->tupdesc); @@ -1545,10 +1544,9 @@ exec_stmt_fors(PLpgSQL_execstate *estate, PLpgSQL_stmt_fors *stmt) } /* - * otherwise, we processed a labelled exit that does - * not match the current statement's label, if any: - * return RC_EXIT so that the EXIT continues to - * recurse upward. + * otherwise, we processed a labelled exit that does not + * match the current statement's label, if any: return + * RC_EXIT so that the EXIT continues to recurse upward. */ } else if (rc == PLPGSQL_RC_CONTINUE) @@ -1569,16 +1567,16 @@ exec_stmt_fors(PLpgSQL_execstate *estate, PLpgSQL_stmt_fors *stmt) } /* - * otherwise, we processed a named continue - * that does not match the current statement's - * label, if any: return RC_CONTINUE so that the - * CONTINUE will propagate up the stack. + * otherwise, we processed a named continue that does not + * match the current statement's label, if any: return + * RC_CONTINUE so that the CONTINUE will propagate up the + * stack. */ } /* - * We're aborting the loop, so cleanup and set FOUND. - * (This code should match the code after the loop.) + * We're aborting the loop, so cleanup and set FOUND. (This + * code should match the code after the loop.) */ SPI_freetuptable(tuptab); SPI_cursor_close(portal); @@ -1610,9 +1608,9 @@ exec_stmt_fors(PLpgSQL_execstate *estate, PLpgSQL_stmt_fors *stmt) /* * Set the FOUND variable to indicate the result of executing the loop - * (namely, whether we looped one or more times). This must be set - * here so that it does not interfere with the value of the FOUND - * variable inside the loop processing itself. + * (namely, whether we looped one or more times). This must be set here so + * that it does not interfere with the value of the FOUND variable inside + * the loop processing itself. */ exec_set_found(estate, found); @@ -1626,7 +1624,7 @@ exec_stmt_fors(PLpgSQL_execstate *estate, PLpgSQL_stmt_fors *stmt) * ---------- */ static int -exec_stmt_select(PLpgSQL_execstate *estate, PLpgSQL_stmt_select *stmt) +exec_stmt_select(PLpgSQL_execstate * estate, PLpgSQL_stmt_select * stmt) { PLpgSQL_rec *rec = NULL; PLpgSQL_row *row = NULL; @@ -1656,8 +1654,7 @@ exec_stmt_select(PLpgSQL_execstate *estate, PLpgSQL_stmt_select *stmt) n = estate->eval_processed; /* - * If the query didn't return any rows, set the target to NULL and - * return. + * If the query didn't return any rows, set the target to NULL and return. */ if (n == 0) { @@ -1685,7 +1682,7 @@ exec_stmt_select(PLpgSQL_execstate *estate, PLpgSQL_stmt_select *stmt) * ---------- */ static int -exec_stmt_exit(PLpgSQL_execstate *estate, PLpgSQL_stmt_exit *stmt) +exec_stmt_exit(PLpgSQL_execstate * estate, PLpgSQL_stmt_exit * stmt) { /* * If the exit / continue has a condition, evaluate it @@ -1715,12 +1712,12 @@ exec_stmt_exit(PLpgSQL_execstate *estate, PLpgSQL_stmt_exit *stmt) * ---------- */ static int -exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt) +exec_stmt_return(PLpgSQL_execstate * estate, PLpgSQL_stmt_return * stmt) { /* * If processing a set-returning PL/PgSQL function, the final RETURN - * indicates that the function is finished producing tuples. The rest - * of the work will be done at the top level. + * indicates that the function is finished producing tuples. The rest of + * the work will be done at the top level. */ if (estate->retisset) return PLPGSQL_RC_RETURN; @@ -1737,41 +1734,41 @@ exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt) switch (retvar->dtype) { case PLPGSQL_DTYPE_VAR: - { - PLpgSQL_var *var = (PLpgSQL_var *) retvar; + { + PLpgSQL_var *var = (PLpgSQL_var *) retvar; - estate->retval = var->value; - estate->retisnull = var->isnull; - estate->rettype = var->datatype->typoid; - } - break; + estate->retval = var->value; + estate->retisnull = var->isnull; + estate->rettype = var->datatype->typoid; + } + break; case PLPGSQL_DTYPE_REC: - { - PLpgSQL_rec *rec = (PLpgSQL_rec *) retvar; - - if (HeapTupleIsValid(rec->tup)) { - estate->retval = (Datum) rec->tup; - estate->rettupdesc = rec->tupdesc; - estate->retisnull = false; + PLpgSQL_rec *rec = (PLpgSQL_rec *) retvar; + + if (HeapTupleIsValid(rec->tup)) + { + estate->retval = (Datum) rec->tup; + estate->rettupdesc = rec->tupdesc; + estate->retisnull = false; + } } - } - break; + break; case PLPGSQL_DTYPE_ROW: - { - PLpgSQL_row *row = (PLpgSQL_row *) retvar; - - Assert(row->rowtupdesc); - estate->retval = (Datum) make_tuple_from_row(estate, row, - row->rowtupdesc); - if (estate->retval == (Datum) NULL) /* should not happen */ - elog(ERROR, "row not compatible with its own tupdesc"); - estate->rettupdesc = row->rowtupdesc; - estate->retisnull = false; - } - break; + { + PLpgSQL_row *row = (PLpgSQL_row *) retvar; + + Assert(row->rowtupdesc); + estate->retval = (Datum) make_tuple_from_row(estate, row, + row->rowtupdesc); + if (estate->retval == (Datum) NULL) /* should not happen */ + elog(ERROR, "row not compatible with its own tupdesc"); + estate->rettupdesc = row->rowtupdesc; + estate->retisnull = false; + } + break; default: elog(ERROR, "unrecognized dtype: %d", retvar->dtype); @@ -1806,8 +1803,8 @@ exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt) /* * Special hack for function returning VOID: instead of NULL, return a * non-null VOID value. This is of dubious importance but is kept for - * backwards compatibility. Note that the only other way to get here - * is to have written "RETURN NULL" in a function returning tuple. + * backwards compatibility. Note that the only other way to get here is + * to have written "RETURN NULL" in a function returning tuple. */ if (estate->fn_rettype == VOIDOID) { @@ -1826,8 +1823,8 @@ exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt) * ---------- */ static int -exec_stmt_return_next(PLpgSQL_execstate *estate, - PLpgSQL_stmt_return_next *stmt) +exec_stmt_return_next(PLpgSQL_execstate * estate, + PLpgSQL_stmt_return_next * stmt) { TupleDesc tupdesc; int natts; @@ -1837,7 +1834,7 @@ exec_stmt_return_next(PLpgSQL_execstate *estate, if (!estate->retisset) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("cannot use RETURN NEXT in a non-SETOF function"))); + errmsg("cannot use RETURN NEXT in a non-SETOF function"))); if (estate->tuple_store == NULL) exec_init_tuple_store(estate); @@ -1853,59 +1850,59 @@ exec_stmt_return_next(PLpgSQL_execstate *estate, switch (retvar->dtype) { case PLPGSQL_DTYPE_VAR: - { - PLpgSQL_var *var = (PLpgSQL_var *) retvar; - Datum retval = var->value; - bool isNull = var->isnull; + { + PLpgSQL_var *var = (PLpgSQL_var *) retvar; + Datum retval = var->value; + bool isNull = var->isnull; - if (natts != 1) - ereport(ERROR, - (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("wrong result type supplied in RETURN NEXT"))); + if (natts != 1) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("wrong result type supplied in RETURN NEXT"))); - /* coerce type if needed */ - retval = exec_simple_cast_value(retval, - var->datatype->typoid, - tupdesc->attrs[0]->atttypid, + /* coerce type if needed */ + retval = exec_simple_cast_value(retval, + var->datatype->typoid, + tupdesc->attrs[0]->atttypid, tupdesc->attrs[0]->atttypmod, - isNull); + isNull); - tuple = heap_form_tuple(tupdesc, &retval, &isNull); + tuple = heap_form_tuple(tupdesc, &retval, &isNull); - free_tuple = true; - } - break; + free_tuple = true; + } + break; case PLPGSQL_DTYPE_REC: - { - PLpgSQL_rec *rec = (PLpgSQL_rec *) retvar; + { + PLpgSQL_rec *rec = (PLpgSQL_rec *) retvar; - if (!HeapTupleIsValid(rec->tup)) - ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("record \"%s\" is not assigned yet", - rec->refname), - errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); - if (!compatible_tupdesc(tupdesc, rec->tupdesc)) - ereport(ERROR, - (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("wrong record type supplied in RETURN NEXT"))); - tuple = rec->tup; - } - break; + if (!HeapTupleIsValid(rec->tup)) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("record \"%s\" is not assigned yet", + rec->refname), + errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); + if (!compatible_tupdesc(tupdesc, rec->tupdesc)) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("wrong record type supplied in RETURN NEXT"))); + tuple = rec->tup; + } + break; case PLPGSQL_DTYPE_ROW: - { - PLpgSQL_row *row = (PLpgSQL_row *) retvar; + { + PLpgSQL_row *row = (PLpgSQL_row *) retvar; - tuple = make_tuple_from_row(estate, row, tupdesc); - if (tuple == NULL) - ereport(ERROR, - (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("wrong record type supplied in RETURN NEXT"))); - free_tuple = true; - } - break; + tuple = make_tuple_from_row(estate, row, tupdesc); + if (tuple == NULL) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("wrong record type supplied in RETURN NEXT"))); + free_tuple = true; + } + break; default: elog(ERROR, "unrecognized dtype: %d", retvar->dtype); @@ -1922,7 +1919,7 @@ exec_stmt_return_next(PLpgSQL_execstate *estate, if (natts != 1) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("wrong result type supplied in RETURN NEXT"))); + errmsg("wrong result type supplied in RETURN NEXT"))); retval = exec_eval_expr(estate, stmt->expr, @@ -1966,7 +1963,7 @@ exec_stmt_return_next(PLpgSQL_execstate *estate, } static void -exec_init_tuple_store(PLpgSQL_execstate *estate) +exec_init_tuple_store(PLpgSQL_execstate * estate) { ReturnSetInfo *rsi = estate->rsi; MemoryContext oldcxt; @@ -1995,7 +1992,7 @@ exec_init_tuple_store(PLpgSQL_execstate *estate) * ---------- */ static int -exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt) +exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt) { char *cp; PLpgSQL_dstring ds; @@ -2030,7 +2027,7 @@ exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt) errmsg("too few parameters specified for RAISE"))); paramvalue = exec_eval_expr(estate, - (PLpgSQL_expr *) lfirst(current_param), + (PLpgSQL_expr *) lfirst(current_param), ¶misnull, ¶mtypeid); @@ -2048,8 +2045,8 @@ exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt) } /* - * If more parameters were specified than were required to process - * the format string, throw an error + * If more parameters were specified than were required to process the + * format string, throw an error */ if (current_param != NULL) ereport(ERROR, @@ -2062,8 +2059,8 @@ exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt) estate->err_text = raise_skip_msg; /* suppress traceback of raise */ ereport(stmt->elog_level, - ((stmt->elog_level >= ERROR) ? errcode(ERRCODE_RAISE_EXCEPTION) : 0, - errmsg_internal("%s", plpgsql_dstring_get(&ds)))); + ((stmt->elog_level >= ERROR) ? errcode(ERRCODE_RAISE_EXCEPTION) : 0, + errmsg_internal("%s", plpgsql_dstring_get(&ds)))); estate->err_text = NULL; /* un-suppress... */ @@ -2078,8 +2075,8 @@ exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt) * ---------- */ static void -plpgsql_estate_setup(PLpgSQL_execstate *estate, - PLpgSQL_function *func, +plpgsql_estate_setup(PLpgSQL_execstate * estate, + PLpgSQL_function * func, ReturnSetInfo *rsi) { estate->retval = (Datum) 0; @@ -2116,9 +2113,9 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate, estate->err_text = NULL; /* - * Create an EState for evaluation of simple expressions, if there's - * not one already in the current transaction. The EState is made a - * child of TopTransactionContext so it will have the right lifespan. + * Create an EState for evaluation of simple expressions, if there's not + * one already in the current transaction. The EState is made a child of + * TopTransactionContext so it will have the right lifespan. */ if (simple_eval_estate == NULL) { @@ -2130,8 +2127,8 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate, } /* - * Create an expression context for simple expressions. - * This must be a child of simple_eval_estate. + * Create an expression context for simple expressions. This must be a + * child of simple_eval_estate. */ estate->eval_econtext = CreateExprContext(simple_eval_estate); } @@ -2144,7 +2141,7 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate, * ---------- */ static void -exec_eval_cleanup(PLpgSQL_execstate *estate) +exec_eval_cleanup(PLpgSQL_execstate * estate) { /* Clear result of a full SPI_execute */ if (estate->eval_tuptable != NULL) @@ -2162,8 +2159,8 @@ exec_eval_cleanup(PLpgSQL_execstate *estate) * ---------- */ static void -exec_prepare_plan(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr) +exec_prepare_plan(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr) { int i; _SPI_plan *spi_plan; @@ -2198,16 +2195,16 @@ exec_prepare_plan(PLpgSQL_execstate *estate, case SPI_ERROR_COPY: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot COPY to/from client in PL/pgSQL"))); + errmsg("cannot COPY to/from client in PL/pgSQL"))); case SPI_ERROR_CURSOR: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot manipulate cursors directly in PL/pgSQL"), - errhint("Use PL/pgSQL's cursor features instead."))); + errmsg("cannot manipulate cursors directly in PL/pgSQL"), + errhint("Use PL/pgSQL's cursor features instead."))); case SPI_ERROR_TRANSACTION: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot begin/end transactions in PL/pgSQL"), + errmsg("cannot begin/end transactions in PL/pgSQL"), errhint("Use a BEGIN block with an EXCEPTION clause instead."))); default: elog(ERROR, "SPI_prepare failed for \"%s\": %s", @@ -2231,8 +2228,8 @@ exec_prepare_plan(PLpgSQL_execstate *estate, * ---------- */ static int -exec_stmt_execsql(PLpgSQL_execstate *estate, - PLpgSQL_stmt_execsql *stmt) +exec_stmt_execsql(PLpgSQL_execstate * estate, + PLpgSQL_stmt_execsql * stmt) { int i; Datum *values; @@ -2282,9 +2279,9 @@ exec_stmt_execsql(PLpgSQL_execstate *estate, case SPI_OK_UPDATE: /* - * If the INSERT, DELETE, or UPDATE query affected at least - * one tuple, set the magic 'FOUND' variable to true. This - * conforms with the behavior of PL/SQL. + * If the INSERT, DELETE, or UPDATE query affected at least one + * tuple, set the magic 'FOUND' variable to true. This conforms + * with the behavior of PL/SQL. */ exec_set_found(estate, (SPI_processed != 0)); break; @@ -2292,7 +2289,7 @@ exec_stmt_execsql(PLpgSQL_execstate *estate, case SPI_OK_SELECT: ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("SELECT query has no destination for result data"), + errmsg("SELECT query has no destination for result data"), errhint("If you want to discard the results, use PERFORM instead."))); default: @@ -2323,8 +2320,8 @@ exec_stmt_execsql(PLpgSQL_execstate *estate, * ---------- */ static int -exec_stmt_dynexecute(PLpgSQL_execstate *estate, - PLpgSQL_stmt_dynexecute *stmt) +exec_stmt_dynexecute(PLpgSQL_execstate * estate, + PLpgSQL_stmt_dynexecute * stmt) { Datum query; bool isnull = false; @@ -2340,8 +2337,8 @@ exec_stmt_dynexecute(PLpgSQL_execstate *estate, row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]); /* - * First we evaluate the string expression after the EXECUTE keyword. - * It's result is the querystring we have to execute. + * First we evaluate the string expression after the EXECUTE keyword. It's + * result is the querystring we have to execute. */ query = exec_eval_expr(estate, stmt->query, &isnull, &restype); if (isnull) @@ -2356,8 +2353,8 @@ exec_stmt_dynexecute(PLpgSQL_execstate *estate, /* * Call SPI_execute() without preparing a saved plan. The returncode can - * be any standard OK. Note that while a SELECT is allowed, its - * results will be discarded unless an INTO clause is specified. + * be any standard OK. Note that while a SELECT is allowed, its results + * will be discarded unless an INTO clause is specified. */ exec_res = SPI_execute(querystr, estate->readonly_func, 0); @@ -2398,14 +2395,13 @@ exec_stmt_dynexecute(PLpgSQL_execstate *estate, case SPI_OK_SELINTO: /* - * We want to disallow SELECT INTO for now, because its - * behavior is not consistent with SELECT INTO in a normal - * plpgsql context. (We need to reimplement EXECUTE to parse - * the string as a plpgsql command, not just feed it to - * SPI_execute.) However, CREATE AS should be allowed ... and - * since it produces the same parsetree as SELECT INTO, - * there's no way to tell the difference except to look at the - * source text. Wotta kluge! + * We want to disallow SELECT INTO for now, because its behavior + * is not consistent with SELECT INTO in a normal plpgsql context. + * (We need to reimplement EXECUTE to parse the string as a + * plpgsql command, not just feed it to SPI_execute.) However, + * CREATE AS should be allowed ... and since it produces the same + * parsetree as SELECT INTO, there's no way to tell the difference + * except to look at the source text. Wotta kluge! */ { char *ptr; @@ -2428,13 +2424,13 @@ exec_stmt_dynexecute(PLpgSQL_execstate *estate, case SPI_ERROR_CURSOR: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot manipulate cursors directly in PL/pgSQL"), + errmsg("cannot manipulate cursors directly in PL/pgSQL"), errhint("Use PL/pgSQL's cursor features instead."))); case SPI_ERROR_TRANSACTION: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot begin/end transactions in PL/pgSQL"), - errhint("Use a BEGIN block with an EXCEPTION clause instead."))); + errhint("Use a BEGIN block with an EXCEPTION clause instead."))); default: elog(ERROR, "SPI_execute failed executing query \"%s\": %s", @@ -2462,7 +2458,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate *estate, * ---------- */ static int -exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt) +exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt) { Datum query; bool isnull; @@ -2487,8 +2483,8 @@ exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt) elog(ERROR, "unsupported target"); /* - * Evaluate the string expression after the EXECUTE keyword. It's - * result is the querystring we have to execute. + * Evaluate the string expression after the EXECUTE keyword. It's result + * is the querystring we have to execute. */ query = exec_eval_expr(estate, stmt->query, &isnull, &restype); if (isnull) @@ -2524,8 +2520,8 @@ exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt) n = SPI_processed; /* - * If the query didn't return any rows, set the target to NULL and - * return with FOUND = false. + * If the query didn't return any rows, set the target to NULL and return + * with FOUND = false. */ if (n == 0) exec_move_row(estate, rec, row, NULL, tuptab->tupdesc); @@ -2541,7 +2537,7 @@ exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt) for (i = 0; i < n; i++) { - int rc; + int rc; /* * Assign the tuple to the target @@ -2569,10 +2565,9 @@ exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt) } /* - * otherwise, we processed a labelled exit that does - * not match the current statement's label, if any: - * return RC_EXIT so that the EXIT continues to - * recurse upward. + * otherwise, we processed a labelled exit that does not + * match the current statement's label, if any: return + * RC_EXIT so that the EXIT continues to recurse upward. */ } else if (rc == PLPGSQL_RC_CONTINUE) @@ -2589,15 +2584,15 @@ exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt) } /* - * otherwise, we process a labelled continue that - * does not match the current statement's label, - * so propagate RC_CONTINUE upward in the stack. + * otherwise, we process a labelled continue that does not + * match the current statement's label, so propagate + * RC_CONTINUE upward in the stack. */ } /* - * We're aborting the loop, so cleanup and set FOUND. - * (This code should match the code after the loop.) + * We're aborting the loop, so cleanup and set FOUND. (This + * code should match the code after the loop.) */ SPI_freetuptable(tuptab); SPI_cursor_close(portal); @@ -2629,9 +2624,9 @@ exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt) /* * Set the FOUND variable to indicate the result of executing the loop - * (namely, whether we looped one or more times). This must be set - * here so that it does not interfere with the value of the FOUND - * variable inside the loop processing itself. + * (namely, whether we looped one or more times). This must be set here so + * that it does not interfere with the value of the FOUND variable inside + * the loop processing itself. */ exec_set_found(estate, found); @@ -2644,7 +2639,7 @@ exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt) * ---------- */ static int -exec_stmt_open(PLpgSQL_execstate *estate, PLpgSQL_stmt_open *stmt) +exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) { PLpgSQL_var *curvar = NULL; char *curname = NULL; @@ -2765,7 +2760,7 @@ exec_stmt_open(PLpgSQL_execstate *estate, PLpgSQL_stmt_open *stmt) if (curvar->cursor_explicit_argrow < 0) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("arguments given for cursor without arguments"))); + errmsg("arguments given for cursor without arguments"))); memset(&set_args, 0, sizeof(set_args)); set_args.cmd_type = PLPGSQL_STMT_SELECT; @@ -2846,7 +2841,7 @@ exec_stmt_open(PLpgSQL_execstate *estate, PLpgSQL_stmt_open *stmt) * ---------- */ static int -exec_stmt_fetch(PLpgSQL_execstate *estate, PLpgSQL_stmt_fetch *stmt) +exec_stmt_fetch(PLpgSQL_execstate * estate, PLpgSQL_stmt_fetch * stmt) { PLpgSQL_var *curvar = NULL; PLpgSQL_rec *rec = NULL; @@ -2864,7 +2859,7 @@ exec_stmt_fetch(PLpgSQL_execstate *estate, PLpgSQL_stmt_fetch *stmt) if (curvar->isnull) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), - errmsg("cursor variable \"%s\" is NULL", curvar->refname))); + errmsg("cursor variable \"%s\" is NULL", curvar->refname))); curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value)); portal = SPI_cursor_find(curname); @@ -2919,7 +2914,7 @@ exec_stmt_fetch(PLpgSQL_execstate *estate, PLpgSQL_stmt_fetch *stmt) * ---------- */ static int -exec_stmt_close(PLpgSQL_execstate *estate, PLpgSQL_stmt_close *stmt) +exec_stmt_close(PLpgSQL_execstate * estate, PLpgSQL_stmt_close * stmt) { PLpgSQL_var *curvar = NULL; Portal portal; @@ -2933,7 +2928,7 @@ exec_stmt_close(PLpgSQL_execstate *estate, PLpgSQL_stmt_close *stmt) if (curvar->isnull) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), - errmsg("cursor variable \"%s\" is NULL", curvar->refname))); + errmsg("cursor variable \"%s\" is NULL", curvar->refname))); curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value)); portal = SPI_cursor_find(curname); @@ -2959,8 +2954,8 @@ exec_stmt_close(PLpgSQL_execstate *estate, PLpgSQL_stmt_close *stmt) * ---------- */ static void -exec_assign_expr(PLpgSQL_execstate *estate, PLpgSQL_datum *target, - PLpgSQL_expr *expr) +exec_assign_expr(PLpgSQL_execstate * estate, PLpgSQL_datum * target, + PLpgSQL_expr * expr) { Datum value; Oid valtype; @@ -2977,8 +2972,8 @@ exec_assign_expr(PLpgSQL_execstate *estate, PLpgSQL_datum *target, * ---------- */ static void -exec_assign_value(PLpgSQL_execstate *estate, - PLpgSQL_datum *target, +exec_assign_value(PLpgSQL_execstate * estate, + PLpgSQL_datum * target, Datum value, Oid valtype, bool *isNull) { switch (target->dtype) @@ -3005,10 +3000,10 @@ exec_assign_value(PLpgSQL_execstate *estate, /* * If type is by-reference, make sure we have a freshly - * palloc'd copy; the originally passed value may not live - * as long as the variable! But we don't need to re-copy - * if exec_cast_value performed a conversion; its output - * must already be palloc'd. + * palloc'd copy; the originally passed value may not live as + * long as the variable! But we don't need to re-copy if + * exec_cast_value performed a conversion; its output must + * already be palloc'd. */ if (!var->datatype->typbyval && !*isNull) { @@ -3019,10 +3014,10 @@ exec_assign_value(PLpgSQL_execstate *estate, } /* - * Now free the old value. (We can't do this any earlier - * because of the possibility that we are assigning the - * var's old value to it, eg "foo := foo". We could optimize - * out the assignment altogether in such cases, but it's too + * Now free the old value. (We can't do this any earlier + * because of the possibility that we are assigning the var's + * old value to it, eg "foo := foo". We could optimize out + * the assignment altogether in such cases, but it's too * infrequent to be worth testing for.) */ free_var(var); @@ -3139,16 +3134,16 @@ exec_assign_value(PLpgSQL_execstate *estate, rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]); /* - * Check that there is already a tuple in the record. We - * need that because records don't have any predefined - * field structure. + * Check that there is already a tuple in the record. We need + * that because records don't have any predefined field + * structure. */ if (!HeapTupleIsValid(rec->tup)) ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("record \"%s\" is not assigned yet", - rec->refname), - errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("record \"%s\" is not assigned yet", + rec->refname), + errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); /* * Get the number of the records field to change and the @@ -3164,9 +3159,9 @@ exec_assign_value(PLpgSQL_execstate *estate, natts = rec->tupdesc->natts; /* - * Set up values/datums arrays for heap_formtuple. For - * all the attributes except the one we want to replace, - * use the value that's in the old tuple. + * Set up values/datums arrays for heap_formtuple. For all + * the attributes except the one we want to replace, use the + * value that's in the old tuple. */ values = palloc(sizeof(Datum) * natts); nulls = palloc(natts); @@ -3184,8 +3179,8 @@ exec_assign_value(PLpgSQL_execstate *estate, } /* - * Now insert the new value, being careful to cast it to - * the right type. + * Now insert the new value, being careful to cast it to the + * right type. */ atttype = SPI_gettypeid(rec->tupdesc, fno + 1); atttypmod = rec->tupdesc->attrs[fno]->atttypmod; @@ -3201,8 +3196,8 @@ exec_assign_value(PLpgSQL_execstate *estate, nulls[fno] = ' '; /* - * Avoid leaking the result of exec_simple_cast_value, if - * it performed a conversion to a pass-by-ref type. + * Avoid leaking the result of exec_simple_cast_value, if it + * performed a conversion to a pass-by-ref type. */ if (!attisnull && values[fno] != value && !get_typbyval(atttype)) mustfree = DatumGetPointer(values[fno]); @@ -3251,12 +3246,12 @@ exec_assign_value(PLpgSQL_execstate *estate, /* * Target is an element of an array * - * To handle constructs like x[1][2] := something, we have to - * be prepared to deal with a chain of arrayelem datums. - * Chase back to find the base array datum, and save the - * subscript expressions as we go. (We are scanning right - * to left here, but want to evaluate the subscripts - * left-to-right to minimize surprises.) + * To handle constructs like x[1][2] := something, we have to be + * prepared to deal with a chain of arrayelem datums. Chase + * back to find the base array datum, and save the subscript + * expressions as we go. (We are scanning right to left here, + * but want to evaluate the subscripts left-to-right to + * minimize surprises.) */ nsubscripts = 0; do @@ -3274,13 +3269,13 @@ exec_assign_value(PLpgSQL_execstate *estate, /* Fetch current value of array datum */ exec_eval_datum(estate, target, InvalidOid, - &arraytypeid, &oldarraydatum, &oldarrayisnull); + &arraytypeid, &oldarraydatum, &oldarrayisnull); arrayelemtypeid = get_element_type(arraytypeid); if (!OidIsValid(arrayelemtypeid)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("subscripted object is not an array"))); + errmsg("subscripted object is not an array"))); get_typlenbyvalalign(arrayelemtypeid, &elemtyplen, @@ -3289,8 +3284,7 @@ exec_assign_value(PLpgSQL_execstate *estate, arraytyplen = get_typlen(arraytypeid); /* - * Evaluate the subscripts, switch into left-to-right - * order + * Evaluate the subscripts, switch into left-to-right order */ havenullsubscript = false; for (i = 0; i < nsubscripts; i++) @@ -3313,12 +3307,12 @@ exec_assign_value(PLpgSQL_execstate *estate, return; /* - * If the original array is null, cons up an empty array - * so that the assignment can proceed; we'll end with a + * If the original array is null, cons up an empty array so + * that the assignment can proceed; we'll end with a * one-element array containing just the assigned-to - * subscript. This only works for varlena arrays, though; - * for fixed-length array types we skip the assignment. - * Again, this corresponds to the current behavior of + * subscript. This only works for varlena arrays, though; for + * fixed-length array types we skip the assignment. Again, + * this corresponds to the current behavior of * ExecEvalArrayRef(). */ if (oldarrayisnull) @@ -3363,8 +3357,8 @@ exec_assign_value(PLpgSQL_execstate *estate, arraytypeid, isNull); /* - * Avoid leaking the result of exec_simple_cast_value, if - * it performed a conversion to a pass-by-ref type. + * Avoid leaking the result of exec_simple_cast_value, if it + * performed a conversion to a pass-by-ref type. */ if (!*isNull && coerced_value != value && !elemtypbyval) pfree(DatumGetPointer(coerced_value)); @@ -3391,13 +3385,13 @@ exec_assign_value(PLpgSQL_execstate *estate, * At present this doesn't handle PLpgSQL_expr or PLpgSQL_arrayelem datums. * * NOTE: caller must not modify the returned value, since it points right - * at the stored value in the case of pass-by-reference datatypes. In some + * at the stored value in the case of pass-by-reference datatypes. In some * cases we have to palloc a return value, and in such cases we put it into * the estate's short-term memory context. */ static void -exec_eval_datum(PLpgSQL_execstate *estate, - PLpgSQL_datum *datum, +exec_eval_datum(PLpgSQL_execstate * estate, + PLpgSQL_datum * datum, Oid expectedtypeid, Oid *typeid, Datum *value, @@ -3454,19 +3448,18 @@ exec_eval_datum(PLpgSQL_execstate *estate, if (!HeapTupleIsValid(rec->tup)) ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("record \"%s\" is not assigned yet", - rec->refname), - errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("record \"%s\" is not assigned yet", + rec->refname), + errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); Assert(rec->tupdesc != NULL); /* Make sure we have a valid type/typmod setting */ BlessTupleDesc(rec->tupdesc); /* - * In a trigger, the NEW and OLD parameters are likely to - * be on-disk tuples that don't have the desired Datum - * fields. Copy the tuple body and insert the right - * values. + * In a trigger, the NEW and OLD parameters are likely to be + * on-disk tuples that don't have the desired Datum fields. + * Copy the tuple body and insert the right values. */ oldcontext = MemoryContextSwitchTo(estate->eval_econtext->ecxt_per_tuple_memory); heap_copytuple_with_tuple(rec->tup, &worktup); @@ -3494,10 +3487,10 @@ exec_eval_datum(PLpgSQL_execstate *estate, rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]); if (!HeapTupleIsValid(rec->tup)) ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("record \"%s\" is not assigned yet", - rec->refname), - errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("record \"%s\" is not assigned yet", + rec->refname), + errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); fno = SPI_fnumber(rec->tupdesc, recfield->fieldname); if (fno == SPI_ERROR_NOATTRIBUTE) ereport(ERROR, @@ -3555,8 +3548,8 @@ exec_eval_datum(PLpgSQL_execstate *estate, * ---------- */ static int -exec_eval_integer(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, +exec_eval_integer(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, bool *isNull) { Datum exprdatum; @@ -3577,8 +3570,8 @@ exec_eval_integer(PLpgSQL_execstate *estate, * ---------- */ static bool -exec_eval_boolean(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, +exec_eval_boolean(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, bool *isNull) { Datum exprdatum; @@ -3599,8 +3592,8 @@ exec_eval_boolean(PLpgSQL_execstate *estate, * ---------- */ static Datum -exec_eval_expr(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, +exec_eval_expr(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, bool *isNull, Oid *rettype) { @@ -3623,7 +3616,7 @@ exec_eval_expr(PLpgSQL_execstate *estate, if (rc != SPI_OK_SELECT) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("query \"%s\" did not return data", expr->query))); + errmsg("query \"%s\" did not return data", expr->query))); /* * If there are no rows selected, the result is NULL. @@ -3662,8 +3655,8 @@ exec_eval_expr(PLpgSQL_execstate *estate, * ---------- */ static int -exec_run_select(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, long maxtuples, Portal *portalP) +exec_run_select(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, long maxtuples, Portal *portalP) { int i; Datum *values; @@ -3744,8 +3737,8 @@ exec_run_select(PLpgSQL_execstate *estate, * ---------- */ static Datum -exec_eval_simple_expr(PLpgSQL_execstate *estate, - PLpgSQL_expr *expr, +exec_eval_simple_expr(PLpgSQL_execstate * estate, + PLpgSQL_expr * expr, bool *isNull, Oid *rettype) { @@ -3761,8 +3754,8 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate, *rettype = expr->expr_simple_type; /* - * Prepare the expression for execution, if it's not been done already - * in the current transaction. + * Prepare the expression for execution, if it's not been done already in + * the current transaction. */ if (expr->expr_simple_state == NULL) { @@ -3776,14 +3769,14 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate, /* * Param list can live in econtext's temporary memory context. * - * XXX think about avoiding repeated palloc's for param lists? Beware - * however that this routine is re-entrant: exec_eval_datum() can call - * it back for subscript evaluation, and so there can be a need to - * have more than one active param list. + * XXX think about avoiding repeated palloc's for param lists? Beware however + * that this routine is re-entrant: exec_eval_datum() can call it back for + * subscript evaluation, and so there can be a need to have more than one + * active param list. */ paramLI = (ParamListInfo) MemoryContextAlloc(econtext->ecxt_per_tuple_memory, - (expr->nparams + 1) * sizeof(ParamListInfoData)); + (expr->nparams + 1) * sizeof(ParamListInfoData)); /* * Put the parameter values into the parameter list entries. @@ -3806,10 +3799,10 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate, econtext->ecxt_param_list_info = paramLI; /* - * We have to do some of the things SPI_execute_plan would do, - * in particular advance the snapshot if we are in a non-read-only - * function. Without this, stable functions within the expression - * would fail to see updates made so far by our own function. + * We have to do some of the things SPI_execute_plan would do, in + * particular advance the snapshot if we are in a non-read-only function. + * Without this, stable functions within the expression would fail to see + * updates made so far by our own function. */ SPI_push(); saveActiveSnapshot = ActiveSnapshot; @@ -3857,9 +3850,9 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate, * ---------- */ static void -exec_move_row(PLpgSQL_execstate *estate, - PLpgSQL_rec *rec, - PLpgSQL_row *row, +exec_move_row(PLpgSQL_execstate * estate, + PLpgSQL_rec * rec, + PLpgSQL_row * row, HeapTuple tup, TupleDesc tupdesc) { /* @@ -3923,16 +3916,16 @@ exec_move_row(PLpgSQL_execstate *estate, * Row is a bit more complicated in that we assign the individual * attributes of the tuple to the variables the row points to. * - * NOTE: this code used to demand row->nfields == tup->t_data->t_natts, - * but that's wrong. The tuple might have more fields than we - * expected if it's from an inheritance-child table of the current - * table, or it might have fewer if the table has had columns added by - * ALTER TABLE. Ignore extra columns and assume NULL for missing - * columns, the same as heap_getattr would do. We also have to skip - * over dropped columns in either the source or destination. + * NOTE: this code used to demand row->nfields == tup->t_data->t_natts, but + * that's wrong. The tuple might have more fields than we expected if + * it's from an inheritance-child table of the current table, or it might + * have fewer if the table has had columns added by ALTER TABLE. Ignore + * extra columns and assume NULL for missing columns, the same as + * heap_getattr would do. We also have to skip over dropped columns in + * either the source or destination. * - * If we have no tuple data at all, we'll assign NULL to all columns of - * the row variable. + * If we have no tuple data at all, we'll assign NULL to all columns of the + * row variable. */ if (row != NULL) { @@ -3991,8 +3984,8 @@ exec_move_row(PLpgSQL_execstate *estate, * ---------- */ static HeapTuple -make_tuple_from_row(PLpgSQL_execstate *estate, - PLpgSQL_row *row, +make_tuple_from_row(PLpgSQL_execstate * estate, + PLpgSQL_row * row, TupleDesc tupdesc) { int natts = tupdesc->natts; @@ -4066,8 +4059,8 @@ exec_cast_value(Datum value, Oid valtype, if (!isnull) { /* - * If the type of the queries return value isn't that of the - * variable, convert it. + * If the type of the queries return value isn't that of the variable, + * convert it. */ if (valtype != reqtype || reqtypmod != -1) { @@ -4358,7 +4351,7 @@ exec_simple_check_node(Node *node) * ---------- */ static void -exec_simple_check_plan(PLpgSQL_expr *expr) +exec_simple_check_plan(PLpgSQL_expr * expr) { _SPI_plan *spi_plan = (_SPI_plan *) expr->plan; Plan *plan; @@ -4367,8 +4360,8 @@ exec_simple_check_plan(PLpgSQL_expr *expr) expr->expr_simple_expr = NULL; /* - * 1. We can only evaluate queries that resulted in one single - * execution plan + * 1. We can only evaluate queries that resulted in one single execution + * plan */ if (list_length(spi_plan->ptlist) != 1) return; @@ -4445,7 +4438,7 @@ compatible_tupdesc(TupleDesc td1, TupleDesc td2) * ---------- */ static void -exec_set_found(PLpgSQL_execstate *estate, bool state) +exec_set_found(PLpgSQL_execstate * estate, bool state) { PLpgSQL_var *var; @@ -4481,10 +4474,10 @@ plpgsql_xact_cb(XactEvent event, void *arg) active_simple_exprs = NULL; /* - * If we are doing a clean transaction shutdown, free the - * EState (so that any remaining resources will be released - * correctly). In an abort, we expect the regular abort - * recovery procedures to release everything of interest. + * If we are doing a clean transaction shutdown, free the EState (so that + * any remaining resources will be released correctly). In an abort, we + * expect the regular abort recovery procedures to release everything of + * interest. */ if (event == XACT_EVENT_COMMIT && simple_eval_estate) FreeExecutorState(simple_eval_estate); @@ -4492,7 +4485,7 @@ plpgsql_xact_cb(XactEvent event, void *arg) } static void -free_var(PLpgSQL_var *var) +free_var(PLpgSQL_var * var) { if (var->freeval) { diff --git a/src/pl/plpgsql/src/pl_funcs.c b/src/pl/plpgsql/src/pl_funcs.c index 03280c94b12..dd12a061f34 100644 --- a/src/pl/plpgsql/src/pl_funcs.c +++ b/src/pl/plpgsql/src/pl_funcs.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.45 2005/06/22 01:35:02 neilc Exp $ + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.46 2005/10/15 02:49:50 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -56,7 +56,7 @@ static bool ns_localmode = false; * ---------- */ void -plpgsql_dstring_init(PLpgSQL_dstring *ds) +plpgsql_dstring_init(PLpgSQL_dstring * ds) { ds->value = palloc(ds->alloc = 512); ds->used = 1; @@ -69,13 +69,13 @@ plpgsql_dstring_init(PLpgSQL_dstring *ds) * ---------- */ void -plpgsql_dstring_free(PLpgSQL_dstring *ds) +plpgsql_dstring_free(PLpgSQL_dstring * ds) { pfree(ds->value); } static void -plpgsql_dstring_expand(PLpgSQL_dstring *ds, int needed) +plpgsql_dstring_expand(PLpgSQL_dstring * ds, int needed) { /* Don't allow truncating the string */ Assert(needed > ds->alloc); @@ -94,7 +94,7 @@ plpgsql_dstring_expand(PLpgSQL_dstring *ds, int needed) * ---------- */ void -plpgsql_dstring_append(PLpgSQL_dstring *ds, const char *str) +plpgsql_dstring_append(PLpgSQL_dstring * ds, const char *str) { int len = strlen(str); int needed = ds->used + len; @@ -113,7 +113,7 @@ plpgsql_dstring_append(PLpgSQL_dstring *ds, const char *str) * ---------- */ void -plpgsql_dstring_append_char(PLpgSQL_dstring *ds, char c) +plpgsql_dstring_append_char(PLpgSQL_dstring * ds, char c) { if (ds->used == ds->alloc) plpgsql_dstring_expand(ds, ds->used + 1); @@ -129,7 +129,7 @@ plpgsql_dstring_append_char(PLpgSQL_dstring *ds, char c) * ---------- */ char * -plpgsql_dstring_get(PLpgSQL_dstring *ds) +plpgsql_dstring_get(PLpgSQL_dstring * ds) { return ds->value; } @@ -229,7 +229,7 @@ plpgsql_ns_additem(int itemtype, int itemno, const char *name) { ns->items_alloc *= 2; ns->items = repalloc(ns->items, - sizeof(PLpgSQL_nsitem *) * ns->items_alloc); + sizeof(PLpgSQL_nsitem *) * ns->items_alloc); } } @@ -310,8 +310,8 @@ plpgsql_ns_rename(char *oldname, char *newname) int i; /* - * Lookup name in the namestack; do the lookup in the current - * namespace only. + * Lookup name in the namestack; do the lookup in the current namespace + * only. */ for (ns = ns_current; ns != NULL; ns = ns->upper) { @@ -416,8 +416,8 @@ plpgsql_convert_ident(const char *s, char **output, int numidents) else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("qualified identifier cannot be used here: %s", - sstart))); + errmsg("qualified identifier cannot be used here: %s", + sstart))); /* If not done, skip whitespace, dot, whitespace */ if (*s) @@ -443,7 +443,7 @@ plpgsql_convert_ident(const char *s, char **output, int numidents) * Statement type as a string, for use in error messages etc. */ const char * -plpgsql_stmt_typename(PLpgSQL_stmt *stmt) +plpgsql_stmt_typename(PLpgSQL_stmt * stmt) { switch (stmt->cmd_type) { @@ -499,28 +499,28 @@ plpgsql_stmt_typename(PLpgSQL_stmt *stmt) static int dump_indent; static void dump_ind(); -static void dump_stmt(PLpgSQL_stmt *stmt); -static void dump_block(PLpgSQL_stmt_block *block); -static void dump_assign(PLpgSQL_stmt_assign *stmt); -static void dump_if(PLpgSQL_stmt_if *stmt); -static void dump_loop(PLpgSQL_stmt_loop *stmt); -static void dump_while(PLpgSQL_stmt_while *stmt); -static void dump_fori(PLpgSQL_stmt_fori *stmt); -static void dump_fors(PLpgSQL_stmt_fors *stmt); -static void dump_select(PLpgSQL_stmt_select *stmt); -static void dump_exit(PLpgSQL_stmt_exit *stmt); -static void dump_return(PLpgSQL_stmt_return *stmt); -static void dump_return_next(PLpgSQL_stmt_return_next *stmt); -static void dump_raise(PLpgSQL_stmt_raise *stmt); -static void dump_execsql(PLpgSQL_stmt_execsql *stmt); -static void dump_dynexecute(PLpgSQL_stmt_dynexecute *stmt); -static void dump_dynfors(PLpgSQL_stmt_dynfors *stmt); -static void dump_getdiag(PLpgSQL_stmt_getdiag *stmt); -static void dump_open(PLpgSQL_stmt_open *stmt); -static void dump_fetch(PLpgSQL_stmt_fetch *stmt); -static void dump_close(PLpgSQL_stmt_close *stmt); -static void dump_perform(PLpgSQL_stmt_perform *stmt); -static void dump_expr(PLpgSQL_expr *expr); +static void dump_stmt(PLpgSQL_stmt * stmt); +static void dump_block(PLpgSQL_stmt_block * block); +static void dump_assign(PLpgSQL_stmt_assign * stmt); +static void dump_if(PLpgSQL_stmt_if * stmt); +static void dump_loop(PLpgSQL_stmt_loop * stmt); +static void dump_while(PLpgSQL_stmt_while * stmt); +static void dump_fori(PLpgSQL_stmt_fori * stmt); +static void dump_fors(PLpgSQL_stmt_fors * stmt); +static void dump_select(PLpgSQL_stmt_select * stmt); +static void dump_exit(PLpgSQL_stmt_exit * stmt); +static void dump_return(PLpgSQL_stmt_return * stmt); +static void dump_return_next(PLpgSQL_stmt_return_next * stmt); +static void dump_raise(PLpgSQL_stmt_raise * stmt); +static void dump_execsql(PLpgSQL_stmt_execsql * stmt); +static void dump_dynexecute(PLpgSQL_stmt_dynexecute * stmt); +static void dump_dynfors(PLpgSQL_stmt_dynfors * stmt); +static void dump_getdiag(PLpgSQL_stmt_getdiag * stmt); +static void dump_open(PLpgSQL_stmt_open * stmt); +static void dump_fetch(PLpgSQL_stmt_fetch * stmt); +static void dump_close(PLpgSQL_stmt_close * stmt); +static void dump_perform(PLpgSQL_stmt_perform * stmt); +static void dump_expr(PLpgSQL_expr * expr); static void @@ -533,7 +533,7 @@ dump_ind(void) } static void -dump_stmt(PLpgSQL_stmt *stmt) +dump_stmt(PLpgSQL_stmt * stmt) { printf("%3d:", stmt->lineno); switch (stmt->cmd_type) @@ -607,16 +607,16 @@ dump_stmt(PLpgSQL_stmt *stmt) static void dump_stmts(List *stmts) { - ListCell *s; + ListCell *s; dump_indent += 2; - foreach (s, stmts) + foreach(s, stmts) dump_stmt((PLpgSQL_stmt *) lfirst(s)); dump_indent -= 2; } static void -dump_block(PLpgSQL_stmt_block *block) +dump_block(PLpgSQL_stmt_block * block) { char *name; @@ -632,9 +632,9 @@ dump_block(PLpgSQL_stmt_block *block) if (block->exceptions) { - ListCell *e; + ListCell *e; - foreach (e, block->exceptions->exc_list) + foreach(e, block->exceptions->exc_list) { PLpgSQL_exception *exc = (PLpgSQL_exception *) lfirst(e); PLpgSQL_condition *cond; @@ -657,7 +657,7 @@ dump_block(PLpgSQL_stmt_block *block) } static void -dump_assign(PLpgSQL_stmt_assign *stmt) +dump_assign(PLpgSQL_stmt_assign * stmt) { dump_ind(); printf("ASSIGN var %d := ", stmt->varno); @@ -666,7 +666,7 @@ dump_assign(PLpgSQL_stmt_assign *stmt) } static void -dump_if(PLpgSQL_stmt_if *stmt) +dump_if(PLpgSQL_stmt_if * stmt) { dump_ind(); printf("IF "); @@ -687,7 +687,7 @@ dump_if(PLpgSQL_stmt_if *stmt) } static void -dump_loop(PLpgSQL_stmt_loop *stmt) +dump_loop(PLpgSQL_stmt_loop * stmt) { dump_ind(); printf("LOOP\n"); @@ -699,7 +699,7 @@ dump_loop(PLpgSQL_stmt_loop *stmt) } static void -dump_while(PLpgSQL_stmt_while *stmt) +dump_while(PLpgSQL_stmt_while * stmt) { dump_ind(); printf("WHILE "); @@ -713,7 +713,7 @@ dump_while(PLpgSQL_stmt_while *stmt) } static void -dump_fori(PLpgSQL_stmt_fori *stmt) +dump_fori(PLpgSQL_stmt_fori * stmt) { dump_ind(); printf("FORI %s %s\n", stmt->var->refname, (stmt->reverse) ? "REVERSE" : "NORMAL"); @@ -736,7 +736,7 @@ dump_fori(PLpgSQL_stmt_fori *stmt) } static void -dump_fors(PLpgSQL_stmt_fors *stmt) +dump_fors(PLpgSQL_stmt_fors * stmt) { dump_ind(); printf("FORS %s ", (stmt->rec != NULL) ? stmt->rec->refname : stmt->row->refname); @@ -750,7 +750,7 @@ dump_fors(PLpgSQL_stmt_fors *stmt) } static void -dump_select(PLpgSQL_stmt_select *stmt) +dump_select(PLpgSQL_stmt_select * stmt) { dump_ind(); printf("SELECT "); @@ -773,7 +773,7 @@ dump_select(PLpgSQL_stmt_select *stmt) } static void -dump_open(PLpgSQL_stmt_open *stmt) +dump_open(PLpgSQL_stmt_open * stmt) { dump_ind(); printf("OPEN curvar=%d\n", stmt->curvar); @@ -805,7 +805,7 @@ dump_open(PLpgSQL_stmt_open *stmt) } static void -dump_fetch(PLpgSQL_stmt_fetch *stmt) +dump_fetch(PLpgSQL_stmt_fetch * stmt) { dump_ind(); printf("FETCH curvar=%d\n", stmt->curvar); @@ -826,14 +826,14 @@ dump_fetch(PLpgSQL_stmt_fetch *stmt) } static void -dump_close(PLpgSQL_stmt_close *stmt) +dump_close(PLpgSQL_stmt_close * stmt) { dump_ind(); printf("CLOSE curvar=%d\n", stmt->curvar); } static void -dump_perform(PLpgSQL_stmt_perform *stmt) +dump_perform(PLpgSQL_stmt_perform * stmt) { dump_ind(); printf("PERFORM expr = "); @@ -842,7 +842,7 @@ dump_perform(PLpgSQL_stmt_perform *stmt) } static void -dump_exit(PLpgSQL_stmt_exit *stmt) +dump_exit(PLpgSQL_stmt_exit * stmt) { dump_ind(); printf("%s label='%s'", @@ -856,7 +856,7 @@ dump_exit(PLpgSQL_stmt_exit *stmt) } static void -dump_return(PLpgSQL_stmt_return *stmt) +dump_return(PLpgSQL_stmt_return * stmt) { dump_ind(); printf("RETURN "); @@ -870,7 +870,7 @@ dump_return(PLpgSQL_stmt_return *stmt) } static void -dump_return_next(PLpgSQL_stmt_return_next *stmt) +dump_return_next(PLpgSQL_stmt_return_next * stmt) { dump_ind(); printf("RETURN NEXT "); @@ -884,15 +884,15 @@ dump_return_next(PLpgSQL_stmt_return_next *stmt) } static void -dump_raise(PLpgSQL_stmt_raise *stmt) +dump_raise(PLpgSQL_stmt_raise * stmt) { - ListCell *lc; - int i = 0; + ListCell *lc; + int i = 0; dump_ind(); printf("RAISE '%s'\n", stmt->message); dump_indent += 2; - foreach (lc, stmt->params) + foreach(lc, stmt->params) { dump_ind(); printf(" parameter %d: ", i++); @@ -903,7 +903,7 @@ dump_raise(PLpgSQL_stmt_raise *stmt) } static void -dump_execsql(PLpgSQL_stmt_execsql *stmt) +dump_execsql(PLpgSQL_stmt_execsql * stmt) { dump_ind(); printf("EXECSQL "); @@ -912,7 +912,7 @@ dump_execsql(PLpgSQL_stmt_execsql *stmt) } static void -dump_dynexecute(PLpgSQL_stmt_dynexecute *stmt) +dump_dynexecute(PLpgSQL_stmt_dynexecute * stmt) { dump_ind(); printf("EXECUTE "); @@ -934,7 +934,7 @@ dump_dynexecute(PLpgSQL_stmt_dynexecute *stmt) } static void -dump_dynfors(PLpgSQL_stmt_dynfors *stmt) +dump_dynfors(PLpgSQL_stmt_dynfors * stmt) { dump_ind(); printf("FORS %s EXECUTE ", (stmt->rec != NULL) ? stmt->rec->refname : stmt->row->refname); @@ -948,13 +948,13 @@ dump_dynfors(PLpgSQL_stmt_dynfors *stmt) } static void -dump_getdiag(PLpgSQL_stmt_getdiag *stmt) +dump_getdiag(PLpgSQL_stmt_getdiag * stmt) { - ListCell *lc; + ListCell *lc; dump_ind(); printf("GET DIAGNOSTICS "); - foreach (lc, stmt->diag_items) + foreach(lc, stmt->diag_items) { PLpgSQL_diag_item *diag_item = (PLpgSQL_diag_item *) lfirst(lc); @@ -982,7 +982,7 @@ dump_getdiag(PLpgSQL_stmt_getdiag *stmt) } static void -dump_expr(PLpgSQL_expr *expr) +dump_expr(PLpgSQL_expr * expr) { int i; @@ -1002,7 +1002,7 @@ dump_expr(PLpgSQL_expr *expr) } void -plpgsql_dumptree(PLpgSQL_function *func) +plpgsql_dumptree(PLpgSQL_function * func) { int i; PLpgSQL_datum *d; diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c index c20efe77391..69d128e8698 100644 --- a/src/pl/plpgsql/src/pl_handler.c +++ b/src/pl/plpgsql/src/pl_handler.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.25 2005/03/29 00:17:23 tgl Exp $ + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.26 2005/10/15 02:49:50 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -47,7 +47,7 @@ extern DLLIMPORT bool check_function_bodies; -static bool plpgsql_firstcall = true; +static bool plpgsql_firstcall = true; static void plpgsql_init_all(void); @@ -118,7 +118,7 @@ plpgsql_call_handler(PG_FUNCTION_ARGS) */ if (CALLED_AS_TRIGGER(fcinfo)) retval = PointerGetDatum(plpgsql_exec_trigger(func, - (TriggerData *) fcinfo->context)); + (TriggerData *) fcinfo->context)); else retval = plpgsql_exec_function(func, fcinfo); @@ -198,7 +198,7 @@ plpgsql_validator(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("plpgsql functions cannot take type %s", - format_type_be(proc->proargtypes.values[i])))); + format_type_be(proc->proargtypes.values[i])))); } } diff --git a/src/pl/plpgsql/src/plpgsql.h b/src/pl/plpgsql/src/plpgsql.h index 3615b3bf066..38b1aa1329b 100644 --- a/src/pl/plpgsql/src/plpgsql.h +++ b/src/pl/plpgsql/src/plpgsql.h @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.64 2005/06/22 01:35:02 neilc Exp $ + * $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.65 2005/10/15 02:49:50 momjian Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -150,7 +150,7 @@ typedef struct int alloc; int used; /* Including NUL terminator */ char *value; -} PLpgSQL_dstring; +} PLpgSQL_dstring; typedef struct @@ -164,7 +164,7 @@ typedef struct Oid typioparam; FmgrInfo typinput; /* lookup info for typinput function */ int32 atttypmod; /* typmod (taken from someplace else) */ -} PLpgSQL_type; +} PLpgSQL_type; /* @@ -176,7 +176,7 @@ typedef struct { /* Generic datum array item */ int dtype; int dno; -} PLpgSQL_datum; +} PLpgSQL_datum; /* * The variants PLpgSQL_var, PLpgSQL_row, and PLpgSQL_rec share these @@ -188,7 +188,7 @@ typedef struct int dno; char *refname; int lineno; -} PLpgSQL_variable; +} PLpgSQL_variable; typedef struct PLpgSQL_expr { /* SQL Query to plan and execute */ @@ -206,7 +206,7 @@ typedef struct PLpgSQL_expr /* params to pass to expr */ int nparams; int params[1]; /* VARIABLE SIZE ARRAY ... must be last */ -} PLpgSQL_expr; +} PLpgSQL_expr; typedef struct @@ -226,7 +226,7 @@ typedef struct Datum value; bool isnull; bool freeval; -} PLpgSQL_var; +} PLpgSQL_var; typedef struct @@ -248,7 +248,7 @@ typedef struct int nfields; char **fieldnames; int *varnos; -} PLpgSQL_row; +} PLpgSQL_row; typedef struct @@ -262,7 +262,7 @@ typedef struct TupleDesc tupdesc; bool freetup; bool freetupdesc; -} PLpgSQL_rec; +} PLpgSQL_rec; typedef struct @@ -271,7 +271,7 @@ typedef struct int rfno; char *fieldname; int recparentno; /* dno of parent record */ -} PLpgSQL_recfield; +} PLpgSQL_recfield; typedef struct @@ -280,7 +280,7 @@ typedef struct int dno; PLpgSQL_expr *subscript; int arrayparentno; /* dno of parent array variable */ -} PLpgSQL_arrayelem; +} PLpgSQL_arrayelem; typedef struct @@ -288,7 +288,7 @@ typedef struct int dtype; int dno; PLpgSQL_expr *argnum; -} PLpgSQL_trigarg; +} PLpgSQL_trigarg; typedef struct @@ -296,7 +296,7 @@ typedef struct int itemtype; int itemno; char name[1]; -} PLpgSQL_nsitem; +} PLpgSQL_nsitem; /* XXX: consider adapting this to use List */ @@ -306,14 +306,14 @@ typedef struct PLpgSQL_ns int items_used; PLpgSQL_nsitem **items; struct PLpgSQL_ns *upper; -} PLpgSQL_ns; +} PLpgSQL_ns; typedef struct { /* Generic execution node */ int cmd_type; int lineno; -} PLpgSQL_stmt; +} PLpgSQL_stmt; typedef struct PLpgSQL_condition @@ -321,21 +321,21 @@ typedef struct PLpgSQL_condition int sqlerrstate; /* SQLSTATE code */ char *condname; /* condition name (for debugging) */ struct PLpgSQL_condition *next; -} PLpgSQL_condition; +} PLpgSQL_condition; typedef struct { int sqlstate_varno; int sqlerrm_varno; List *exc_list; /* List of WHEN clauses */ -} PLpgSQL_exception_block; +} PLpgSQL_exception_block; typedef struct { /* One EXCEPTION ... WHEN clause */ int lineno; PLpgSQL_condition *conditions; List *action; /* List of statements */ -} PLpgSQL_exception; +} PLpgSQL_exception; typedef struct @@ -347,7 +347,7 @@ typedef struct int n_initvars; int *initvarnos; PLpgSQL_exception_block *exceptions; -} PLpgSQL_stmt_block; +} PLpgSQL_stmt_block; typedef struct @@ -356,27 +356,27 @@ typedef struct int lineno; int varno; PLpgSQL_expr *expr; -} PLpgSQL_stmt_assign; +} PLpgSQL_stmt_assign; typedef struct { /* PERFORM statement */ int cmd_type; int lineno; PLpgSQL_expr *expr; -} PLpgSQL_stmt_perform; +} PLpgSQL_stmt_perform; typedef struct { /* Get Diagnostics item */ int kind; /* id for diagnostic value desired */ int target; /* where to assign it */ -} PLpgSQL_diag_item; +} PLpgSQL_diag_item; typedef struct { /* Get Diagnostics statement */ int cmd_type; int lineno; List *diag_items; /* List of PLpgSQL_diag_item */ -} PLpgSQL_stmt_getdiag; +} PLpgSQL_stmt_getdiag; typedef struct @@ -386,7 +386,7 @@ typedef struct PLpgSQL_expr *cond; List *true_body; /* List of statements */ List *false_body; /* List of statements */ -} PLpgSQL_stmt_if; +} PLpgSQL_stmt_if; typedef struct @@ -395,7 +395,7 @@ typedef struct int lineno; char *label; List *body; /* List of statements */ -} PLpgSQL_stmt_loop; +} PLpgSQL_stmt_loop; typedef struct @@ -405,7 +405,7 @@ typedef struct char *label; PLpgSQL_expr *cond; List *body; /* List of statements */ -} PLpgSQL_stmt_while; +} PLpgSQL_stmt_while; typedef struct @@ -418,7 +418,7 @@ typedef struct PLpgSQL_expr *upper; int reverse; List *body; /* List of statements */ -} PLpgSQL_stmt_fori; +} PLpgSQL_stmt_fori; typedef struct @@ -430,7 +430,7 @@ typedef struct PLpgSQL_row *row; PLpgSQL_expr *query; List *body; /* List of statements */ -} PLpgSQL_stmt_fors; +} PLpgSQL_stmt_fors; typedef struct @@ -442,7 +442,7 @@ typedef struct PLpgSQL_row *row; PLpgSQL_expr *query; List *body; /* List of statements */ -} PLpgSQL_stmt_dynfors; +} PLpgSQL_stmt_dynfors; typedef struct @@ -452,7 +452,7 @@ typedef struct PLpgSQL_rec *rec; PLpgSQL_row *row; PLpgSQL_expr *query; -} PLpgSQL_stmt_select; +} PLpgSQL_stmt_select; typedef struct @@ -464,7 +464,7 @@ typedef struct PLpgSQL_expr *argquery; PLpgSQL_expr *query; PLpgSQL_expr *dynquery; -} PLpgSQL_stmt_open; +} PLpgSQL_stmt_open; typedef struct @@ -474,7 +474,7 @@ typedef struct PLpgSQL_rec *rec; PLpgSQL_row *row; int curvar; -} PLpgSQL_stmt_fetch; +} PLpgSQL_stmt_fetch; typedef struct @@ -482,7 +482,7 @@ typedef struct int cmd_type; int lineno; int curvar; -} PLpgSQL_stmt_close; +} PLpgSQL_stmt_close; typedef struct @@ -492,7 +492,7 @@ typedef struct bool is_exit; /* Is this an exit or a continue? */ char *label; PLpgSQL_expr *cond; -} PLpgSQL_stmt_exit; +} PLpgSQL_stmt_exit; typedef struct @@ -501,7 +501,7 @@ typedef struct int lineno; PLpgSQL_expr *expr; int retvarno; -} PLpgSQL_stmt_return; +} PLpgSQL_stmt_return; typedef struct { /* RETURN NEXT statement */ @@ -509,7 +509,7 @@ typedef struct int lineno; PLpgSQL_expr *expr; int retvarno; -} PLpgSQL_stmt_return_next; +} PLpgSQL_stmt_return_next; typedef struct { /* RAISE statement */ @@ -518,7 +518,7 @@ typedef struct int elog_level; char *message; List *params; /* list of expressions */ -} PLpgSQL_stmt_raise; +} PLpgSQL_stmt_raise; typedef struct @@ -526,17 +526,17 @@ typedef struct int cmd_type; int lineno; PLpgSQL_expr *sqlstmt; -} PLpgSQL_stmt_execsql; +} PLpgSQL_stmt_execsql; typedef struct { /* Dynamic SQL string to execute */ int cmd_type; int lineno; - PLpgSQL_rec *rec; /* INTO record or row variable */ + PLpgSQL_rec *rec; /* INTO record or row variable */ PLpgSQL_row *row; PLpgSQL_expr *query; -} PLpgSQL_stmt_dynexecute; +} PLpgSQL_stmt_dynexecute; typedef struct PLpgSQL_func_hashkey @@ -544,20 +544,19 @@ typedef struct PLpgSQL_func_hashkey Oid funcOid; /* - * For a trigger function, the OID of the relation triggered on is - * part of the hashkey --- we want to compile the trigger separately - * for each relation it is used with, in case the rowtype is - * different. Zero if not called as a trigger. + * For a trigger function, the OID of the relation triggered on is part of + * the hashkey --- we want to compile the trigger separately for each + * relation it is used with, in case the rowtype is different. Zero if + * not called as a trigger. */ Oid trigrelOid; /* - * We include actual argument types in the hash key to support - * polymorphic PLpgSQL functions. Be careful that extra positions are - * zeroed! + * We include actual argument types in the hash key to support polymorphic + * PLpgSQL functions. Be careful that extra positions are zeroed! */ Oid argtypes[FUNC_MAX_ARGS]; -} PLpgSQL_func_hashkey; +} PLpgSQL_func_hashkey; typedef struct PLpgSQL_function @@ -596,7 +595,7 @@ typedef struct PLpgSQL_function int ndatums; PLpgSQL_datum **datums; PLpgSQL_stmt_block *action; -} PLpgSQL_function; +} PLpgSQL_function; typedef struct @@ -612,8 +611,8 @@ typedef struct bool readonly_func; TupleDesc rettupdesc; - char *exitlabel; /* the "target" label of the current - * EXIT or CONTINUE stmt, if any */ + char *exitlabel; /* the "target" label of the current EXIT or + * CONTINUE stmt, if any */ Tuplestorestate *tuple_store; /* SRFs accumulate results here */ MemoryContext tuple_store_cxt; @@ -636,15 +635,15 @@ typedef struct PLpgSQL_function *err_func; /* current func */ PLpgSQL_stmt *err_stmt; /* current stmt */ const char *err_text; /* additional state info */ -} PLpgSQL_execstate; +} PLpgSQL_execstate; /********************************************************************** * Global variable declarations **********************************************************************/ -extern bool plpgsql_DumpExecTree; -extern bool plpgsql_SpaceScanned; +extern bool plpgsql_DumpExecTree; +extern bool plpgsql_SpaceScanned; extern int plpgsql_nDatums; extern PLpgSQL_datum **plpgsql_Datums; @@ -657,7 +656,7 @@ extern char *plpgsql_base_yytext; #define plpgsql_yytext plpgsql_base_yytext extern PLpgSQL_function *plpgsql_curr_compile; -extern bool plpgsql_check_syntax; +extern bool plpgsql_check_syntax; extern MemoryContext compile_tmp_cxt; /********************************************************************** @@ -681,10 +680,10 @@ extern int plpgsql_parse_dblwordrowtype(char *word); extern PLpgSQL_type *plpgsql_parse_datatype(const char *string); extern PLpgSQL_type *plpgsql_build_datatype(Oid typeOid, int32 typmod); extern PLpgSQL_variable *plpgsql_build_variable(const char *refname, int lineno, - PLpgSQL_type *dtype, + PLpgSQL_type * dtype, bool add2namespace); extern PLpgSQL_condition *plpgsql_parse_err_condition(char *condname); -extern void plpgsql_adddatum(PLpgSQL_datum *new); +extern void plpgsql_adddatum(PLpgSQL_datum * new); extern int plpgsql_add_initdatums(int **varnos); extern void plpgsql_HashTableInit(void); extern void plpgsql_compile_error_callback(void *arg); @@ -701,9 +700,9 @@ extern Datum plpgsql_validator(PG_FUNCTION_ARGS); * Functions in pl_exec.c * ---------- */ -extern Datum plpgsql_exec_function(PLpgSQL_function *func, +extern Datum plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo); -extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function *func, +extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function * func, TriggerData *trigdata); extern void plpgsql_xact_cb(XactEvent event, void *arg); @@ -711,11 +710,11 @@ extern void plpgsql_xact_cb(XactEvent event, void *arg); * Functions for the dynamic string handling in pl_funcs.c * ---------- */ -extern void plpgsql_dstring_init(PLpgSQL_dstring *ds); -extern void plpgsql_dstring_free(PLpgSQL_dstring *ds); -extern void plpgsql_dstring_append(PLpgSQL_dstring *ds, const char *str); -extern void plpgsql_dstring_append_char(PLpgSQL_dstring *ds, char c); -extern char *plpgsql_dstring_get(PLpgSQL_dstring *ds); +extern void plpgsql_dstring_init(PLpgSQL_dstring * ds); +extern void plpgsql_dstring_free(PLpgSQL_dstring * ds); +extern void plpgsql_dstring_append(PLpgSQL_dstring * ds, const char *str); +extern void plpgsql_dstring_append_char(PLpgSQL_dstring * ds, char c); +extern char *plpgsql_dstring_get(PLpgSQL_dstring * ds); /* ---------- * Functions for the namestack handling in pl_funcs.c @@ -734,8 +733,8 @@ extern void plpgsql_ns_rename(char *oldname, char *newname); * ---------- */ extern void plpgsql_convert_ident(const char *s, char **output, int numidents); -extern const char *plpgsql_stmt_typename(PLpgSQL_stmt *stmt); -extern void plpgsql_dumptree(PLpgSQL_function *func); +extern const char *plpgsql_stmt_typename(PLpgSQL_stmt * stmt); +extern void plpgsql_dumptree(PLpgSQL_function * func); /* ---------- * Externs in gram.y and scan.l |
