@@ -867,9 +867,6 @@ exec_stmt_exec(PLtsql_execstate *estate, PLtsql_stmt_exec *stmt)
867867 /* whether procedure was created WITH RECOMPILE */
868868 bool created_with_recompile = false;
869869
870- /* INSERT EXEC handling - temp table lifecycle */
871- bool insert_exec_setup_done = false;
872-
873870 /*
874871 * We need to disable the explain gucs incase of sp_reset_connection
875872 * execution otherwise we will get explain output for it which is
@@ -901,8 +898,8 @@ exec_stmt_exec(PLtsql_execstate *estate, PLtsql_stmt_exec *stmt)
901898 * Setup INSERT EXEC (new path): create temp table to capture procedure
902899 * output. After procedure completes, temp table is flushed to target.
903900 */
904- if (pltsql_enable_new_insert_exec )
905- insert_exec_setup_done = insert_exec_setup (estate , stmt -> insert_exec , true);
901+ if (stmt -> insert_exec != NULL )
902+ insert_exec_setup (estate , stmt -> insert_exec , true);
906903
907904 if (IS_TDS_CONN ())
908905 {
@@ -1338,12 +1335,12 @@ exec_stmt_exec(PLtsql_execstate *estate, PLtsql_stmt_exec *stmt)
13381335 exec_eval_cleanup (estate );
13391336 SPI_freetuptable (SPI_tuptable );
13401337
1341- if (insert_exec_setup_done )
1338+ if (stmt -> insert_exec != NULL )
13421339 insert_exec_flush_and_cleanup (estate , stmt -> insert_exec );
13431340 }
13441341 PG_FINALLY ();
13451342 {
1346- if (insert_exec_setup_done )
1343+ if (stmt -> insert_exec != NULL )
13471344 pltsql_insert_exec_reset_all ();
13481345
13491346 /*
@@ -1543,9 +1540,6 @@ exec_stmt_exec_batch(PLtsql_execstate *estate, PLtsql_stmt_exec_batch *stmt)
15431540 char * old_db_name = get_cur_db_name ();
15441541 char * cur_db_name = NULL ;
15451542
1546- /* INSERT EXEC handling - temp table lifecycle */
1547- bool insert_exec_setup_done = false;
1548-
15491543 LOCAL_FCINFO (fcinfo , 1 );
15501544
15511545 /*
@@ -1568,8 +1562,8 @@ exec_stmt_exec_batch(PLtsql_execstate *estate, PLtsql_stmt_exec_batch *stmt)
15681562 * output. No implicit transaction for dynamic SQL (different semantics
15691563 * than stored procs).
15701564 */
1571- if (pltsql_enable_new_insert_exec )
1572- insert_exec_setup_done = insert_exec_setup (estate , stmt -> insert_exec , false);
1565+ if (stmt -> insert_exec != NULL )
1566+ insert_exec_setup (estate , stmt -> insert_exec , false);
15731567
15741568 /* Get the C-String representation */
15751569 querystr = convert_value_to_string (estate , query , restype );
@@ -1592,12 +1586,12 @@ exec_stmt_exec_batch(PLtsql_execstate *estate, PLtsql_stmt_exec_batch *stmt)
15921586 if (fcinfo -> isnull )
15931587 elog (ERROR , "pltsql_inline_handler failed" );
15941588
1595- if (insert_exec_setup_done )
1589+ if (stmt -> insert_exec != NULL )
15961590 insert_exec_flush_and_cleanup (estate , stmt -> insert_exec );
15971591 }
15981592 PG_FINALLY ();
15991593 {
1600- if (insert_exec_setup_done )
1594+ if (stmt -> insert_exec != NULL )
16011595 pltsql_insert_exec_reset_all ();
16021596
16031597 /* Restore past settings */
@@ -2224,9 +2218,6 @@ exec_stmt_exec_sp(PLtsql_execstate *estate, PLtsql_stmt_exec_sp *stmt)
22242218 int save_nestlevel ;
22252219 int scope_level ;
22262220 InlineCodeBlockArgs * args = NULL ;
2227-
2228- /* INSERT EXEC handling - temp table lifecycle */
2229- bool insert_exec_setup_done = false;
22302221
22312222 batch = exec_eval_expr (estate , stmt -> query , & isnull1 , & restype1 , & restypmod1 );
22322223 if (isnull1 )
@@ -2279,8 +2270,8 @@ exec_stmt_exec_sp(PLtsql_execstate *estate, PLtsql_stmt_exec_sp *stmt)
22792270 * The procedure output will be redirected to this temp table.
22802271 * After procedure completes, we flush temp table to target and cleanup.
22812272 */
2282- if (pltsql_enable_new_insert_exec )
2283- insert_exec_setup_done = insert_exec_setup (estate , stmt -> insert_exec , true);
2273+ if (stmt -> insert_exec != NULL )
2274+ insert_exec_setup (estate , stmt -> insert_exec , true);
22842275
22852276 if (strcmp (batchstr , "" ) != 0 ) /* check edge cases for
22862277 * sp_executesql */
@@ -2293,12 +2284,12 @@ exec_stmt_exec_sp(PLtsql_execstate *estate, PLtsql_stmt_exec_sp *stmt)
22932284 exec_assign_value (estate , estate -> datums [stmt -> return_code_dno ], Int32GetDatum (ret ), false, INT4OID , 0 );
22942285 }
22952286
2296- if (insert_exec_setup_done )
2287+ if (stmt -> insert_exec != NULL )
22972288 insert_exec_flush_and_cleanup (estate , stmt -> insert_exec );
22982289 }
22992290 PG_FINALLY ();
23002291 {
2301- if (insert_exec_setup_done )
2292+ if (stmt -> insert_exec != NULL )
23022293 pltsql_insert_exec_reset_all ();
23032294
23042295 pltsql_revert_guc (save_nestlevel );
0 commit comments