@@ -2018,157 +2018,180 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
20182018}
20192019
20202020
2021- /* ----------
2022- * exec_stmts Iterate over a list of statements
2023- * as long as their return code is OK
2024- * ----------
2025- */
20262021static int
2027- exec_stmts (PLpgSQL_execstate * estate , List * stmts )
2022+ exec_stmt (PLpgSQL_execstate * estate , PLpgSQL_stmt * stmt )
20282023{
2029- PLpgSQL_stmt * save_estmt = estate -> err_stmt ;
2030- ListCell * s ;
2024+ int rc ;
20312025
2032- if ( stmts == NIL )
2026+ switch ( stmt -> cmd_type )
20332027 {
2034- /*
2035- * Ensure we do a CHECK_FOR_INTERRUPTS() even though there is no
2036- * statement. This prevents hangup in a tight loop if, for instance,
2037- * there is a LOOP construct with an empty body.
2038- */
2039- CHECK_FOR_INTERRUPTS ();
2040- return PLPGSQL_RC_OK ;
2041- }
2028+ case PLPGSQL_STMT_BLOCK :
2029+ rc = exec_stmt_block (estate , (PLpgSQL_stmt_block * ) stmt );
2030+ break ;
20422031
2043- foreach (s , stmts )
2044- {
2045- PLpgSQL_stmt * stmt = (PLpgSQL_stmt * ) lfirst (s );
2046- int rc ;
2032+ case PLPGSQL_STMT_ASSIGN :
2033+ rc = exec_stmt_assign (estate , (PLpgSQL_stmt_assign * ) stmt );
2034+ break ;
20472035
2048- estate -> err_stmt = stmt ;
2036+ case PLPGSQL_STMT_PERFORM :
2037+ rc = exec_stmt_perform (estate , (PLpgSQL_stmt_perform * ) stmt );
2038+ break ;
20492039
2050- /* Let the plugin know that we are about to execute this statement */
2051- if ( * plpgsql_plugin_ptr && ( * plpgsql_plugin_ptr ) -> stmt_beg )
2052- (( * plpgsql_plugin_ptr ) -> stmt_beg ) ( estate , stmt ) ;
2040+ case PLPGSQL_STMT_CALL :
2041+ rc = exec_stmt_call ( estate , ( PLpgSQL_stmt_call * ) stmt );
2042+ break ;
20532043
2054- CHECK_FOR_INTERRUPTS ();
2044+ case PLPGSQL_STMT_GETDIAG :
2045+ rc = exec_stmt_getdiag (estate , (PLpgSQL_stmt_getdiag * ) stmt );
2046+ break ;
20552047
2056- switch (stmt -> cmd_type )
2057- {
2058- case PLPGSQL_STMT_BLOCK :
2059- rc = exec_stmt_block (estate , (PLpgSQL_stmt_block * ) stmt );
2060- break ;
2048+ case PLPGSQL_STMT_IF :
2049+ rc = exec_stmt_if (estate , (PLpgSQL_stmt_if * ) stmt );
2050+ break ;
20612051
2062- case PLPGSQL_STMT_ASSIGN :
2063- rc = exec_stmt_assign (estate , (PLpgSQL_stmt_assign * ) stmt );
2064- break ;
2052+ case PLPGSQL_STMT_CASE :
2053+ rc = exec_stmt_case (estate , (PLpgSQL_stmt_case * ) stmt );
2054+ break ;
20652055
2066- case PLPGSQL_STMT_PERFORM :
2067- rc = exec_stmt_perform (estate , (PLpgSQL_stmt_perform * ) stmt );
2068- break ;
2056+ case PLPGSQL_STMT_LOOP :
2057+ rc = exec_stmt_loop (estate , (PLpgSQL_stmt_loop * ) stmt );
2058+ break ;
20692059
2070- case PLPGSQL_STMT_CALL :
2071- rc = exec_stmt_call (estate , (PLpgSQL_stmt_call * ) stmt );
2072- break ;
2060+ case PLPGSQL_STMT_WHILE :
2061+ rc = exec_stmt_while (estate , (PLpgSQL_stmt_while * ) stmt );
2062+ break ;
20732063
2074- case PLPGSQL_STMT_GETDIAG :
2075- rc = exec_stmt_getdiag (estate , (PLpgSQL_stmt_getdiag * ) stmt );
2076- break ;
2064+ case PLPGSQL_STMT_FORI :
2065+ rc = exec_stmt_fori (estate , (PLpgSQL_stmt_fori * ) stmt );
2066+ break ;
20772067
2078- case PLPGSQL_STMT_IF :
2079- rc = exec_stmt_if (estate , (PLpgSQL_stmt_if * ) stmt );
2080- break ;
2068+ case PLPGSQL_STMT_FORS :
2069+ rc = exec_stmt_fors (estate , (PLpgSQL_stmt_fors * ) stmt );
2070+ break ;
20812071
2082- case PLPGSQL_STMT_CASE :
2083- rc = exec_stmt_case (estate , (PLpgSQL_stmt_case * ) stmt );
2084- break ;
2072+ case PLPGSQL_STMT_FORC :
2073+ rc = exec_stmt_forc (estate , (PLpgSQL_stmt_forc * ) stmt );
2074+ break ;
20852075
2086- case PLPGSQL_STMT_LOOP :
2087- rc = exec_stmt_loop (estate , (PLpgSQL_stmt_loop * ) stmt );
2088- break ;
2076+ case PLPGSQL_STMT_FOREACH_A :
2077+ rc = exec_stmt_foreach_a (estate , (PLpgSQL_stmt_foreach_a * ) stmt );
2078+ break ;
20892079
2090- case PLPGSQL_STMT_WHILE :
2091- rc = exec_stmt_while (estate , (PLpgSQL_stmt_while * ) stmt );
2092- break ;
2080+ case PLPGSQL_STMT_EXIT :
2081+ rc = exec_stmt_exit (estate , (PLpgSQL_stmt_exit * ) stmt );
2082+ break ;
20932083
2094- case PLPGSQL_STMT_FORI :
2095- rc = exec_stmt_fori (estate , (PLpgSQL_stmt_fori * ) stmt );
2096- break ;
2084+ case PLPGSQL_STMT_RETURN :
2085+ rc = exec_stmt_return (estate , (PLpgSQL_stmt_return * ) stmt );
2086+ break ;
20972087
2098- case PLPGSQL_STMT_FORS :
2099- rc = exec_stmt_fors (estate , (PLpgSQL_stmt_fors * ) stmt );
2100- break ;
2088+ case PLPGSQL_STMT_RETURN_NEXT :
2089+ rc = exec_stmt_return_next (estate , (PLpgSQL_stmt_return_next * ) stmt );
2090+ break ;
21012091
2102- case PLPGSQL_STMT_FORC :
2103- rc = exec_stmt_forc (estate , (PLpgSQL_stmt_forc * ) stmt );
2104- break ;
2092+ case PLPGSQL_STMT_RETURN_QUERY :
2093+ rc = exec_stmt_return_query (estate , (PLpgSQL_stmt_return_query * ) stmt );
2094+ break ;
21052095
2106- case PLPGSQL_STMT_FOREACH_A :
2107- rc = exec_stmt_foreach_a (estate , (PLpgSQL_stmt_foreach_a * ) stmt );
2108- break ;
2096+ case PLPGSQL_STMT_RAISE :
2097+ rc = exec_stmt_raise (estate , (PLpgSQL_stmt_raise * ) stmt );
2098+ break ;
21092099
2110- case PLPGSQL_STMT_EXIT :
2111- rc = exec_stmt_exit (estate , (PLpgSQL_stmt_exit * ) stmt );
2112- break ;
2100+ case PLPGSQL_STMT_ASSERT :
2101+ rc = exec_stmt_assert (estate , (PLpgSQL_stmt_assert * ) stmt );
2102+ break ;
21132103
2114- case PLPGSQL_STMT_RETURN :
2115- rc = exec_stmt_return (estate , (PLpgSQL_stmt_return * ) stmt );
2116- break ;
2104+ case PLPGSQL_STMT_EXECSQL :
2105+ rc = exec_stmt_execsql (estate , (PLpgSQL_stmt_execsql * ) stmt );
2106+ break ;
21172107
2118- case PLPGSQL_STMT_RETURN_NEXT :
2119- rc = exec_stmt_return_next (estate , (PLpgSQL_stmt_return_next * ) stmt );
2120- break ;
2108+ case PLPGSQL_STMT_DYNEXECUTE :
2109+ rc = exec_stmt_dynexecute (estate , (PLpgSQL_stmt_dynexecute * ) stmt );
2110+ break ;
21212111
2122- case PLPGSQL_STMT_RETURN_QUERY :
2123- rc = exec_stmt_return_query (estate , (PLpgSQL_stmt_return_query * ) stmt );
2124- break ;
2112+ case PLPGSQL_STMT_DYNFORS :
2113+ rc = exec_stmt_dynfors (estate , (PLpgSQL_stmt_dynfors * ) stmt );
2114+ break ;
21252115
2126- case PLPGSQL_STMT_RAISE :
2127- rc = exec_stmt_raise (estate , (PLpgSQL_stmt_raise * ) stmt );
2128- break ;
2116+ case PLPGSQL_STMT_OPEN :
2117+ rc = exec_stmt_open (estate , (PLpgSQL_stmt_open * ) stmt );
2118+ break ;
21292119
2130- case PLPGSQL_STMT_ASSERT :
2131- rc = exec_stmt_assert (estate , (PLpgSQL_stmt_assert * ) stmt );
2132- break ;
2120+ case PLPGSQL_STMT_FETCH :
2121+ rc = exec_stmt_fetch (estate , (PLpgSQL_stmt_fetch * ) stmt );
2122+ break ;
21332123
2134- case PLPGSQL_STMT_EXECSQL :
2135- rc = exec_stmt_execsql (estate , (PLpgSQL_stmt_execsql * ) stmt );
2136- break ;
2124+ case PLPGSQL_STMT_CLOSE :
2125+ rc = exec_stmt_close (estate , (PLpgSQL_stmt_close * ) stmt );
2126+ break ;
21372127
2138- case PLPGSQL_STMT_DYNEXECUTE :
2139- rc = exec_stmt_dynexecute (estate , (PLpgSQL_stmt_dynexecute * ) stmt );
2140- break ;
2128+ case PLPGSQL_STMT_COMMIT :
2129+ rc = exec_stmt_commit (estate , (PLpgSQL_stmt_commit * ) stmt );
2130+ break ;
21412131
2142- case PLPGSQL_STMT_DYNFORS :
2143- rc = exec_stmt_dynfors (estate , (PLpgSQL_stmt_dynfors * ) stmt );
2144- break ;
2132+ case PLPGSQL_STMT_ROLLBACK :
2133+ rc = exec_stmt_rollback (estate , (PLpgSQL_stmt_rollback * ) stmt );
2134+ break ;
21452135
2146- case PLPGSQL_STMT_OPEN :
2147- rc = exec_stmt_open (estate , (PLpgSQL_stmt_open * ) stmt );
2148- break ;
2136+ default :
2137+ elog (ERROR , "unrecognized cmd_type: %d" , stmt -> cmd_type );
2138+ rc = -1 ; /* keep compiler quiet */
2139+ }
21492140
2150- case PLPGSQL_STMT_FETCH :
2151- rc = exec_stmt_fetch (estate , (PLpgSQL_stmt_fetch * ) stmt );
2152- break ;
2141+ return rc ;
2142+ }
21532143
2154- case PLPGSQL_STMT_CLOSE :
2155- rc = exec_stmt_close (estate , (PLpgSQL_stmt_close * ) stmt );
2156- break ;
2144+ /* ----------
2145+ * exec_stmts Iterate over a list of statements
2146+ * as long as their return code is OK
2147+ * ----------
2148+ */
2149+ static int
2150+ exec_stmts (PLpgSQL_execstate * estate , List * stmts )
2151+ {
2152+ ListCell * s ;
2153+ PLpgSQL_stmt * save_estmt = estate -> err_stmt ;
21572154
2158- case PLPGSQL_STMT_COMMIT :
2159- rc = exec_stmt_commit (estate , (PLpgSQL_stmt_commit * ) stmt );
2160- break ;
2155+ if (stmts == NIL )
2156+ {
2157+ /*
2158+ * Ensure we do a CHECK_FOR_INTERRUPTS() even though there is no
2159+ * statement. This prevents hangup in a tight loop if, for instance,
2160+ * there is a LOOP construct with an empty body.
2161+ */
2162+ CHECK_FOR_INTERRUPTS ();
2163+ return PLPGSQL_RC_OK ;
2164+ }
21612165
2162- case PLPGSQL_STMT_ROLLBACK :
2163- rc = exec_stmt_rollback (estate , (PLpgSQL_stmt_rollback * ) stmt );
2164- break ;
2166+ foreach (s , stmts )
2167+ {
2168+ PLpgSQL_stmt * stmt = (PLpgSQL_stmt * ) lfirst (s );
2169+ int rc ;
21652170
2166- default :
2167- /* point err_stmt to parent, since this one seems corrupt */
2168- estate -> err_stmt = save_estmt ;
2169- elog (ERROR , "unrecognized cmd_type: %d" , stmt -> cmd_type );
2170- rc = -1 ; /* keep compiler quiet */
2171+ estate -> err_stmt = stmt ;
2172+ save_estmt = estate -> err_stmt ;
2173+
2174+
2175+ /* Let the plugin know that we are about to execute this statement */
2176+ if (* plpgsql_plugin_ptr && (* plpgsql_plugin_ptr )-> stmt_beg )
2177+ ((* plpgsql_plugin_ptr )-> stmt_beg ) (estate , stmt );
2178+
2179+ CHECK_FOR_INTERRUPTS ();
2180+
2181+ if (* plpgsql_plugin_ptr )
2182+ {
2183+ PG_TRY ();
2184+ {
2185+ rc = exec_stmt (estate , stmt );
2186+ }
2187+ PG_CATCH ();
2188+ {
2189+ PG_RE_THROW ();
2190+ }
2191+ PG_END_TRY ();
21712192 }
2193+ else
2194+ rc = exec_stmt (estate , stmt );
21722195
21732196 /* Let the plugin know that we have finished executing this statement */
21742197 if (* plpgsql_plugin_ptr && (* plpgsql_plugin_ptr )-> stmt_end )
0 commit comments