Skip to content

Commit d426662

Browse files
Jan WieckJan Wieck
authored andcommitted
Added EXECUTE command to PL/pgSQL for execution of
dynamic SQL and utility statements. Jan
1 parent 16dc9ba commit d426662

File tree

6 files changed

+368
-9
lines changed

6 files changed

+368
-9
lines changed

src/pl/plpgsql/src/gram.y

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* procedural language
55
*
66
* IDENTIFICATION
7-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.10 2000/06/05 07:29:14 tgl Exp $
7+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.11 2000/08/31 13:26:15 wieck Exp $
88
*
99
* This software is copyrighted by Jan Wieck - Hamburg.
1010
*
@@ -113,6 +113,7 @@ static PLpgSQL_expr *make_tupret_expr(PLpgSQL_row *row);
113113
%type <stmt> stmt_assign, stmt_if, stmt_loop, stmt_while, stmt_exit
114114
%type <stmt> stmt_return, stmt_raise, stmt_execsql, stmt_fori
115115
%type <stmt> stmt_fors, stmt_select, stmt_perform
116+
%type <stmt> stmt_dynexecute, stmt_dynfors
116117

117118
%type <dtlist> raise_params
118119
%type <ival> raise_level, raise_param
@@ -134,6 +135,7 @@ static PLpgSQL_expr *make_tupret_expr(PLpgSQL_row *row);
134135
%token K_ELSE
135136
%token K_END
136137
%token K_EXCEPTION
138+
%token K_EXECUTE
137139
%token K_EXIT
138140
%token K_FOR
139141
%token K_FROM
@@ -568,6 +570,10 @@ proc_stmt : pl_block
568570
{ $$ = $1; }
569571
| stmt_execsql
570572
{ $$ = $1; }
573+
| stmt_dynexecute
574+
{ $$ = $1; }
575+
| stmt_dynfors
576+
{ $$ = $1; }
571577
| stmt_perform
572578
{ $$ = $1; }
573579
;
@@ -844,6 +850,35 @@ stmt_fors : opt_label K_FOR lno fors_target K_IN K_SELECT expr_until_loop loop_b
844850
$$ = (PLpgSQL_stmt *)new;
845851
}
846852

853+
stmt_dynfors : opt_label K_FOR lno fors_target K_IN K_EXECUTE expr_until_loop loop_body
854+
{
855+
PLpgSQL_stmt_dynfors *new;
856+
857+
new = malloc(sizeof(PLpgSQL_stmt_dynfors));
858+
memset(new, 0, sizeof(PLpgSQL_stmt_dynfors));
859+
860+
new->cmd_type = PLPGSQL_STMT_DYNFORS;
861+
new->lineno = $3;
862+
new->label = $1;
863+
switch ($4->dtype) {
864+
case PLPGSQL_DTYPE_REC:
865+
new->rec = $4;
866+
break;
867+
case PLPGSQL_DTYPE_ROW:
868+
new->row = (PLpgSQL_row *)$4;
869+
break;
870+
default:
871+
plpgsql_comperrinfo();
872+
elog(ERROR, "unknown dtype %d in stmt_dynfors", $4->dtype);
873+
}
874+
new->query = $7;
875+
new->body = $8;
876+
877+
plpgsql_ns_pop();
878+
879+
$$ = (PLpgSQL_stmt *)new;
880+
}
881+
847882
fors_target : T_RECORD
848883
{
849884
$$ = yylval.rec;
@@ -1028,6 +1063,19 @@ stmt_execsql : execsql_start lno
10281063
}
10291064
;
10301065

1066+
stmt_dynexecute : K_EXECUTE lno expr_until_semi
1067+
{
1068+
PLpgSQL_stmt_dynexecute *new;
1069+
1070+
new = malloc(sizeof(PLpgSQL_stmt_dynexecute));
1071+
new->cmd_type = PLPGSQL_STMT_DYNEXECUTE;
1072+
new->lineno = $2;
1073+
new->query = $3;
1074+
1075+
$$ = (PLpgSQL_stmt *)new;
1076+
}
1077+
;
1078+
10311079
execsql_start : T_WORD
10321080
{ $$ = strdup(yytext); }
10331081
| T_ERROR

src/pl/plpgsql/src/pl_comp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.22 2000/08/03 16:34:57 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.23 2000/08/31 13:26:16 wieck Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -159,8 +159,8 @@ plpgsql_compile(Oid fn_oid, int functype)
159159

160160
function->fn_functype = functype;
161161
function->fn_oid = fn_oid;
162-
function->fn_name = DatumGetCString(DirectFunctionCall1(nameout,
163-
NameGetDatum(&(procStruct->proname))));
162+
function->fn_name = strdup(DatumGetCString(DirectFunctionCall1(nameout,
163+
NameGetDatum(&(procStruct->proname)))));
164164

165165
switch (functype)
166166
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy