Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit afeb8c4

Browse files
committed
Clean up some unnecessary fragility in EXECUTE command.
1 parent f9d6ffc commit afeb8c4

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/pl/plpgsql/src/pl_exec.c

Lines changed: 16 additions & 11 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_exec.c,v 1.33 2000/12/01 20:43:59 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.34 2001/01/04 02:38:02 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -1951,6 +1951,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
19511951
HeapTuple typetup;
19521952
Form_pg_type typeStruct;
19531953
FmgrInfo finfo_output;
1954+
int exec_res;
19541955

19551956
/* ----------
19561957
* First we evaluate the string expression after the
@@ -1960,7 +1961,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
19601961
*/
19611962
query = exec_eval_expr(estate, stmt->query, &isnull, &restype);
19621963
if (isnull)
1963-
elog(ERROR, "cannot EXECUTE NULL-query");
1964+
elog(ERROR, "cannot EXECUTE NULL query");
19641965

19651966
/* ----------
19661967
* Get the C-String representation.
@@ -1986,26 +1987,30 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
19861987

19871988
/* ----------
19881989
* Call SPI_exec() without preparing a saved plan.
1989-
* The returncode can be any OK except for OK_SELECT.
1990+
* The returncode can be any standard OK. Note that
1991+
* while a SELECT is allowed, its results will be discarded.
19901992
* ----------
19911993
*/
1992-
switch(SPI_exec(querystr, 0))
1994+
exec_res = SPI_exec(querystr, 0);
1995+
switch (exec_res)
19931996
{
1994-
case SPI_OK_UTILITY:
1997+
case SPI_OK_SELECT:
19951998
case SPI_OK_SELINTO:
19961999
case SPI_OK_INSERT:
19972000
case SPI_OK_UPDATE:
19982001
case SPI_OK_DELETE:
2002+
case SPI_OK_UTILITY:
19992003
break;
20002004

2001-
case SPI_OK_SELECT:
2002-
elog(ERROR, "unexpected SELECT operation in EXECUTE of query '%s'",
2003-
querystr);
2005+
case 0:
2006+
/* Also allow a zero return, which implies the querystring
2007+
* contained no commands.
2008+
*/
20042009
break;
20052010

20062011
default:
2007-
elog(ERROR, "unexpected error in EXECUTE for query '%s'",
2008-
querystr);
2012+
elog(ERROR, "unexpected error %d in EXECUTE of query '%s'",
2013+
exec_res, querystr);
20092014
break;
20102015
}
20112016

@@ -2095,7 +2100,7 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
20952100
* ----------
20962101
*/
20972102
if (SPI_exec(querystr, 0) != SPI_OK_SELECT)
2098-
elog(ERROR, "FOR ... EXECUTE query '%s' was no SELECT", querystr);
2103+
elog(ERROR, "FOR ... EXECUTE query '%s' was not SELECT", querystr);
20992104
pfree(querystr);
21002105

21012106
n = SPI_processed;

0 commit comments

Comments
 (0)