3
3
* procedural language
4
4
*
5
5
* 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 $
7
7
*
8
8
* This software is copyrighted by Jan Wieck - Hamburg.
9
9
*
@@ -1951,6 +1951,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
1951
1951
HeapTuple typetup ;
1952
1952
Form_pg_type typeStruct ;
1953
1953
FmgrInfo finfo_output ;
1954
+ int exec_res ;
1954
1955
1955
1956
/* ----------
1956
1957
* First we evaluate the string expression after the
@@ -1960,7 +1961,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
1960
1961
*/
1961
1962
query = exec_eval_expr (estate , stmt -> query , & isnull , & restype );
1962
1963
if (isnull )
1963
- elog (ERROR , "cannot EXECUTE NULL- query" );
1964
+ elog (ERROR , "cannot EXECUTE NULL query" );
1964
1965
1965
1966
/* ----------
1966
1967
* Get the C-String representation.
@@ -1986,26 +1987,30 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
1986
1987
1987
1988
/* ----------
1988
1989
* 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.
1990
1992
* ----------
1991
1993
*/
1992
- switch (SPI_exec (querystr , 0 ))
1994
+ exec_res = SPI_exec (querystr , 0 );
1995
+ switch (exec_res )
1993
1996
{
1994
- case SPI_OK_UTILITY :
1997
+ case SPI_OK_SELECT :
1995
1998
case SPI_OK_SELINTO :
1996
1999
case SPI_OK_INSERT :
1997
2000
case SPI_OK_UPDATE :
1998
2001
case SPI_OK_DELETE :
2002
+ case SPI_OK_UTILITY :
1999
2003
break ;
2000
2004
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
+ */
2004
2009
break ;
2005
2010
2006
2011
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 );
2009
2014
break ;
2010
2015
}
2011
2016
@@ -2095,7 +2100,7 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt)
2095
2100
* ----------
2096
2101
*/
2097
2102
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 );
2099
2104
pfree (querystr );
2100
2105
2101
2106
n = SPI_processed ;
0 commit comments