@@ -2730,20 +2730,34 @@ StatementEnd_Internal(PLtsql_execstate *estate, PLtsql_stmt *stmt, bool error)
27302730 * is inside the procedure of an INSERT-EXEC,
27312731 * or if the INSERT itself is an INSERT-EXEC
27322732 * and it just returned error.
2733+ *
2734+ * INSERT EXEC detection covers both paths: the
2735+ * new path uses the global context
2736+ * (pltsql_insert_exec_active), the legacy path
2737+ * uses the per-estate flag (estate->insert_exec).
27332738 */
2734- row_count_valid = !estate -> insert_exec &&
2739+ row_count_valid =
2740+ !(estate -> insert_exec ||
2741+ (pltsql_plugin_handler_ptr -> pltsql_insert_exec_active &&
2742+ pltsql_plugin_handler_ptr -> pltsql_insert_exec_active ())) &&
27352743 !(markErrorFlag &&
27362744 ((PLtsql_stmt_execsql * ) stmt )-> insert_exec );
27372745 }
27382746 else if (plansource -> commandTag == CMDTAG_UPDATE )
27392747 {
27402748 command_type = TDS_CMD_UPDATE ;
2741- row_count_valid = !estate -> insert_exec ;
2749+ row_count_valid =
2750+ !(estate -> insert_exec ||
2751+ (pltsql_plugin_handler_ptr -> pltsql_insert_exec_active &&
2752+ pltsql_plugin_handler_ptr -> pltsql_insert_exec_active ()));
27422753 }
27432754 else if (plansource -> commandTag == CMDTAG_DELETE )
27442755 {
27452756 command_type = TDS_CMD_DELETE ;
2746- row_count_valid = !estate -> insert_exec ;
2757+ row_count_valid =
2758+ !(estate -> insert_exec ||
2759+ (pltsql_plugin_handler_ptr -> pltsql_insert_exec_active &&
2760+ pltsql_plugin_handler_ptr -> pltsql_insert_exec_active ()));
27472761 }
27482762
27492763 /*
@@ -2753,7 +2767,10 @@ StatementEnd_Internal(PLtsql_execstate *estate, PLtsql_stmt *stmt, bool error)
27532767 else if (plansource -> commandTag == CMDTAG_SELECT )
27542768 {
27552769 command_type = TDS_CMD_SELECT ;
2756- row_count_valid = !estate -> insert_exec ;
2770+ row_count_valid =
2771+ !(estate -> insert_exec ||
2772+ (pltsql_plugin_handler_ptr -> pltsql_insert_exec_active &&
2773+ pltsql_plugin_handler_ptr -> pltsql_insert_exec_active ()));
27572774 }
27582775 }
27592776 }
@@ -2776,6 +2793,27 @@ StatementEnd_Internal(PLtsql_execstate *estate, PLtsql_stmt *stmt, bool error)
27762793 {
27772794 is_proc = true;
27782795 command_type = TDS_CMD_EXECUTE ;
2796+ /*
2797+ * For INSERT EXEC, report the row count set in
2798+ * flush_insert_exec_temp_table(). Suppress it when an error is
2799+ * pending: the rows are rolled back, no count is sent to the
2800+ * client, and a counted DONE left pending here would otherwise
2801+ * carry a stale count into the following error DONE token.
2802+ */
2803+ if (!markErrorFlag &&
2804+ stmt -> cmd_type == PLTSQL_STMT_EXEC &&
2805+ ((PLtsql_stmt_exec * ) stmt )-> insert_exec != NULL )
2806+ {
2807+ command_type = TDS_CMD_INSERT ;
2808+ row_count_valid = true;
2809+ }
2810+ else if (!markErrorFlag &&
2811+ stmt -> cmd_type == PLTSQL_STMT_EXEC_BATCH &&
2812+ ((PLtsql_stmt_exec_batch * ) stmt )-> insert_exec != NULL )
2813+ {
2814+ command_type = TDS_CMD_INSERT ;
2815+ row_count_valid = true;
2816+ }
27792817 }
27802818 break ;
27812819 default :
0 commit comments