summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pl/plpgsql/src/gram.y11
-rw-r--r--src/pl/plpgsql/src/pl_comp.c23
2 files changed, 17 insertions, 17 deletions
diff --git a/src/pl/plpgsql/src/gram.y b/src/pl/plpgsql/src/gram.y
index 4e4ff9af70e..2ed2a19eb44 100644
--- a/src/pl/plpgsql/src/gram.y
+++ b/src/pl/plpgsql/src/gram.y
@@ -4,7 +4,7 @@
* procedural language
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.64.4.4 2006/05/21 19:57:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.64.4.5 2007/02/08 18:38:03 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -276,7 +276,6 @@ decl_sect : opt_label
$$.label = $1;
$$.n_initvars = 0;
$$.initvarnos = NULL;
- plpgsql_add_initdatums(NULL);
}
| opt_label decl_start
{
@@ -284,7 +283,6 @@ decl_sect : opt_label
$$.label = $1;
$$.n_initvars = 0;
$$.initvarnos = NULL;
- plpgsql_add_initdatums(NULL);
}
| opt_label decl_start decl_stmts
{
@@ -293,12 +291,16 @@ decl_sect : opt_label
$$.label = $3;
else
$$.label = $1;
+ /* Remember variables declared in decl_stmts */
$$.n_initvars = plpgsql_add_initdatums(&($$.initvarnos));
}
;
decl_start : K_DECLARE
{
+ /* Forget any variables created before block */
+ plpgsql_add_initdatums(NULL);
+ /* Make variable names be local to block */
plpgsql_ns_setlocal(true);
}
;
@@ -986,9 +988,6 @@ for_control : lno for_variable K_IN
-1),
true);
- /* put the for-variable into the local block */
- plpgsql_add_initdatums(NULL);
-
new = malloc(sizeof(PLpgSQL_stmt_fori));
memset(new, 0, sizeof(PLpgSQL_stmt_fori));
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index ff8ec94c851..8c9f6483234 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.83 2004/11/30 03:50:29 neilc Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.83.4.1 2007/02/08 18:38:03 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -590,11 +590,6 @@ do_compile(FunctionCallInfo fcinfo,
function->found_varno = var->dno;
/*
- * Forget about the above created variables
- */
- plpgsql_add_initdatums(NULL);
-
- /*
* Now parse the function's text
*/
parse_rc = plpgsql_yyparse();
@@ -1806,11 +1801,17 @@ plpgsql_adddatum(PLpgSQL_datum *new)
/* ----------
- * plpgsql_add_initdatums Put all datum entries created
- * since the last call into the
- * finishing code block so the
- * block knows which variables to
- * reinitialize when entered.
+ * plpgsql_add_initdatums Make an array of the datum numbers of
+ * all the simple VAR datums created since the last call
+ * to this function.
+ *
+ * If varnos is NULL, we just forget any datum entries created since the
+ * last call.
+ *
+ * This is used around a DECLARE section to create a list of the VARs
+ * that have to be initialized at block entry. Note that VARs can also
+ * be created elsewhere than DECLARE, eg by a FOR-loop, but it is then
+ * the responsibility of special-purpose code to initialize them.
* ----------
*/
int