@@ -167,7 +167,7 @@ def execute_procedure(proc_name, *variables)
167
167
log ( sql , name ) do
168
168
case @connection_options [ :mode ]
169
169
when :dblib
170
- result = ensure_established_connection! { @connection . execute ( sql ) }
170
+ result = ensure_established_connection! { dblib_execute ( sql ) }
171
171
options = { as : :hash , cache_rows : true , timezone : ActiveRecord ::Base . default_timezone || :utc }
172
172
result . each ( options ) do |row |
173
173
r = row . with_indifferent_access
@@ -357,13 +357,7 @@ def sp_executesql_sql(sql, types, params, name)
357
357
def raw_connection_do ( sql )
358
358
case @connection_options [ :mode ]
359
359
when :dblib
360
- result = ensure_established_connection! { @connection . execute ( sql ) }
361
-
362
- # TinyTDS returns false instead of raising an exception if connection fails.
363
- # Getting around this by raising an exception ourselves while this PR
364
- # https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
365
- raise TinyTds ::Error , "failed to execute statement" if result . is_a? ( FalseClass )
366
-
360
+ result = ensure_established_connection! { dblib_execute ( sql ) }
367
361
result . do
368
362
end
369
363
ensure
@@ -428,7 +422,7 @@ def _raw_select(sql, options = {})
428
422
def raw_connection_run ( sql )
429
423
case @connection_options [ :mode ]
430
424
when :dblib
431
- ensure_established_connection! { @connection . execute ( sql ) }
425
+ ensure_established_connection! { dblib_execute ( sql ) }
432
426
end
433
427
end
434
428
@@ -463,6 +457,15 @@ def finish_statement_handle(handle)
463
457
handle
464
458
end
465
459
460
+ def dblib_execute ( sql )
461
+ @connection . execute ( sql ) . tap do |result |
462
+ # TinyTDS returns false instead of raising an exception if connection fails.
463
+ # Getting around this by raising an exception ourselves while this PR
464
+ # https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
465
+ raise TinyTds ::Error , "failed to execute statement" if result . is_a? ( FalseClass )
466
+ end
467
+ end
468
+
466
469
def ensure_established_connection!
467
470
raise TinyTds ::Error , 'SQL Server client is not connected' unless @connection
468
471
0 commit comments