@@ -167,7 +167,7 @@ def execute_procedure(proc_name, *variables)
167167 log ( sql , name ) do
168168 case @connection_options [ :mode ]
169169 when :dblib
170- result = @connection . execute ( sql )
170+ result = dblib_connection_execute ( sql )
171171 options = { as : :hash , cache_rows : true , timezone : ActiveRecord ::Base . default_timezone || :utc }
172172 result . each ( options ) do |row |
173173 r = row . with_indifferent_access
@@ -178,6 +178,15 @@ def execute_procedure(proc_name, *variables)
178178 end
179179 end
180180
181+ # TinyTDS returns false instead of raising an exception if connection fails.
182+ # Getting around this by raising an exception ourselves while this PR
183+ # https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
184+ def dblib_connection_execute ( sql )
185+ result = @connection . execute ( sql )
186+ raise TinyTds ::Error , "failed to execute statement" if result . is_a? ( FalseClass )
187+ result
188+ end
189+
181190 def with_identity_insert_enabled ( table_name )
182191 table_name = quote_table_name ( table_name )
183192 set_identity_insert ( table_name , true )
@@ -357,13 +366,7 @@ def sp_executesql_sql(sql, types, params, name)
357366 def raw_connection_do ( sql )
358367 case @connection_options [ :mode ]
359368 when :dblib
360- result = @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-
369+ result = dblib_connection_execute ( sql )
367370 result . do
368371 end
369372 ensure
@@ -428,7 +431,7 @@ def _raw_select(sql, options = {})
428431 def raw_connection_run ( sql )
429432 case @connection_options [ :mode ]
430433 when :dblib
431- @connection . execute ( sql )
434+ dblib_connection_execute ( sql )
432435 end
433436 end
434437
0 commit comments