@@ -55,9 +55,12 @@ def raw_execute(sql, name = nil, binds = [], prepare: false, async: false, allow
5555 end
5656
5757 def internal_exec_sql_query ( sql , conn )
58+ warn "[EXEC_SQL] run sql=#{ sql } "
5859 handle = raw_connection_run ( sql , conn )
60+ warn "[EXEC_SQL] got handle=#{ handle . object_id } "
5961 handle_to_names_and_values ( handle , ar_result : true )
6062 ensure
63+ warn "[EXEC_SQL] ensure finish handle=#{ handle &.object_id } "
6164 finish_statement_handle ( handle )
6265 end
6366
@@ -429,9 +432,12 @@ def identity_columns(table_name)
429432 # === SQLServer Specific (Selecting) ============================ #
430433
431434 def _raw_select ( sql , conn )
435+ warn "[RAW_SELECT] run sql=#{ sql } "
432436 handle = raw_connection_run ( sql , conn )
437+ warn "[RAW_SELECT] got handle=#{ handle . object_id } "
433438 handle_to_names_and_values ( handle , fetch : :rows )
434439 ensure
440+ warn "[RAW_SELECT] ensure finish handle=#{ handle &.object_id } "
435441 finish_statement_handle ( handle )
436442 end
437443
@@ -464,6 +470,7 @@ def handle_to_names_and_values_dblib(handle, options = {})
464470 end
465471
466472 def handle_to_names_and_values_odbc ( handle , options = { } )
473+ warn "[HANDLE NAMES AND VALUES] handle=#{ handle . object_id } "
467474 @raw_connection . use_utc = ActiveRecord . default_timezone || :utc
468475
469476 if options [ :ar_result ]
@@ -478,14 +485,24 @@ def handle_to_names_and_values_odbc(handle, options = {})
478485 handle . fetch_all || [ ]
479486 end
480487 end
488+ ensure
489+ finish_statement_handle ( handle )
481490 end
482491
483492 def finish_statement_handle ( handle )
493+ return unless handle
494+
484495 case @config [ :mode ] . to_sym
485496 when :dblib
486- handle . cancel if handle
497+ warn "[FINISH] cancel handle=#{ handle . object_id } "
498+ handle . cancel
487499 when :odbc
488- handle . drop if handle && handle . respond_to? ( :drop ) && !handle . finished?
500+ if handle . respond_to? ( :drop ) && !handle . finished?
501+ warn "[FINISH] drop handle=#{ handle . object_id } "
502+ handle . drop
503+ else
504+ warn "[FINISH] skip drop handle=#{ handle . object_id } (finished?=#{ handle . respond_to? ( :finished? ) ? handle . finished? : 'n/a' } )"
505+ end
489506 end
490507
491508 handle
@@ -527,10 +544,12 @@ def execute_dblib_procedure(sql, conn)
527544 def execute_odbc_procedure ( sql , conn )
528545 results = [ ]
529546 handle = nil
547+ warn "[PROC] run sql=#{ sql } "
530548
531549 begin
532550 internal_raw_execute_odbc ( sql , conn ) do |h |
533551 handle = h
552+ warn "[PROC] inside block handle=#{ handle . object_id } "
534553
535554 loop do
536555 rows = handle_to_names_and_values ( handle , fetch : :all )
@@ -539,6 +558,7 @@ def execute_odbc_procedure(sql, conn)
539558 break unless handle_more_results? ( handle )
540559 end
541560 end
561+ warn "[PROC] finish block handle=#{ handle . object_id } "
542562 ensure
543563 finish_statement_handle ( handle )
544564 end
0 commit comments