@@ -965,10 +965,6 @@ def execute(
965965# Executing a new statement. Reset is_stmt_prepared to false
966966 self .is_stmt_prepared = [False ]
967967
968- # Enhanced multi-statement handling - pyodbc approach
969- # Apply SET NOCOUNT ON to all multi-statement queries to prevent result set issues
970- if self ._is_multistatement_query (operation ):
971- operation = self ._add_nocount_to_multistatement_sql (operation )
972968
973969 log ('debug' , "Executing query: %s" , operation )
974970 for i , param in enumerate (parameters ):
@@ -1010,9 +1006,9 @@ def execute(
10101006
10111007 self .last_executed_stmt = operation
10121008
1013- # Update rowcount after execution
1009+ # Update rowcount after execution (before buffering)
10141010 # TODO: rowcount return code from SQL needs to be handled
1015- self . rowcount = ddbc_bindings .DDBCSQLRowCount (self .hstmt )
1011+ initial_rowcount = ddbc_bindings .DDBCSQLRowCount (self .hstmt )
10161012
10171013 # Initialize description after execution
10181014 # After successful execution, initialize description if there are results
@@ -1024,12 +1020,16 @@ def execute(
10241020 # If describe fails, it's likely there are no results (e.g., for INSERT)
10251021 self .description = None
10261022
1027- # Reset rownumber for new result set (only for SELECT statements)
1023+ # Buffer intermediate results automatically (pyODBC-style approach)
1024+ self ._buffer_intermediate_results ()
1025+
1026+ # Set final rowcount based on result type (preserve original rowcount for non-SELECT)
10281027 if self .description : # If we have column descriptions, it's likely a SELECT
10291028 self .rowcount = - 1
10301029 self ._reset_rownumber ()
10311030 else :
1032- self .rowcount = ddbc_bindings .DDBCSQLRowCount (self .hstmt )
1031+ # For non-SELECT statements (INSERT/UPDATE/DELETE), preserve the original rowcount
1032+ self .rowcount = initial_rowcount
10331033 self ._clear_rownumber ()
10341034
10351035 # After successful execution, initialize description if there are results
@@ -2188,11 +2188,11 @@ def tables(self, table=None, catalog=None, schema=None, tableType=None):
21882188 ("table_type" , str , None , 128 , 128 , 0 , False ),
21892189 ("remarks" , str , None , 254 , 254 , 0 , True )
21902190 ]
2191-
2191+
21922192 # Use the helper method to prepare the result set
21932193 return self ._prepare_metadata_result_set (fallback_description = fallback_description )
21942194
21952195 except Exception as e :
21962196 # Log the error and re-raise
21972197 log ('error' , f"Error executing tables query: { e } " )
2198- raise
2198+ raise
0 commit comments