@@ -71,19 +71,27 @@ def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
7171 def execute_procedure ( proc_name , *variables )
7272 vars = variables . map { |v | quote ( v ) } . join ( ', ' )
7373 sql = "EXEC #{ proc_name } #{ vars } " . strip
74+ name = 'Execute Procedure'
7475 results = [ ]
75- log ( sql , 'Execute Procedure' ) do
76- raw_connection_run ( sql ) do |handle |
77- get_rows = lambda {
78- rows = handle_to_names_and_values handle , :fetch => :all
79- rows . each_with_index { |r , i | rows [ i ] = r . with_indifferent_access }
80- results << rows
81- }
82- get_rows . call
83- while handle_more_results? ( handle )
76+ case @connection_options [ :mode ]
77+ when :dblib
78+ results << select ( sql , name ) . map { |r | r . with_indifferent_access }
79+ when :odbc
80+ log ( sql , name ) do
81+ raw_connection_run ( sql ) do |handle |
82+ get_rows = lambda {
83+ rows = handle_to_names_and_values handle , :fetch => :all
84+ rows . each_with_index { |r , i | rows [ i ] = r . with_indifferent_access }
85+ results << rows
86+ }
8487 get_rows . call
88+ while handle_more_results? ( handle )
89+ get_rows . call
90+ end
8591 end
8692 end
93+ when :adonet
94+ results << select ( sql , name ) . map { |r | r . with_indifferent_access }
8795 end
8896 results . many? ? results : results . first
8997 end
@@ -179,7 +187,7 @@ def select(sql, name = nil)
179187 end
180188
181189 def insert_sql ( sql , name = nil , pk = nil , id_value = nil , sequence_name = nil )
182- super || select_value ( "SELECT SCOPE_IDENTITY() AS Ident" )
190+ super || select_value ( "SELECT CAST( SCOPE_IDENTITY() AS bigint ) AS Ident" )
183191 end
184192
185193 def update_sql ( sql , name = nil )
@@ -204,6 +212,8 @@ def do_execute(sql, name = nil)
204212
205213 def raw_connection_do ( sql )
206214 case @connection_options [ :mode ]
215+ when :dblib
216+ @connection . execute ( sql ) . do
207217 when :odbc
208218 @connection . do ( sql )
209219 else :adonet
@@ -227,6 +237,8 @@ def raw_select(sql, name=nil, options={})
227237 def raw_connection_run ( sql )
228238 with_auto_reconnect do
229239 case @connection_options [ :mode ]
240+ when :dblib
241+ @connection . execute ( sql )
230242 when :odbc
231243 block_given? ? @connection . run_block ( sql ) { |handle | yield ( handle ) } : @connection . run ( sql )
232244 else :adonet
@@ -237,6 +249,7 @@ def raw_connection_run(sql)
237249
238250 def handle_more_results? ( handle )
239251 case @connection_options [ :mode ]
252+ when :dblib
240253 when :odbc
241254 handle . more_results
242255 when :adonet
@@ -246,13 +259,24 @@ def handle_more_results?(handle)
246259
247260 def handle_to_names_and_values ( handle , options = { } )
248261 case @connection_options [ :mode ]
262+ when :dblib
263+ handle_to_names_and_values_dblib ( handle , options )
249264 when :odbc
250265 handle_to_names_and_values_odbc ( handle , options )
251266 when :adonet
252267 handle_to_names_and_values_adonet ( handle , options )
253268 end
254269 end
255-
270+
271+ def handle_to_names_and_values_dblib ( handle , options = { } )
272+ query_options = { } . tap do |qo |
273+ qo [ :timezone ] = ActiveRecord ::Base . default_timezone || :utc
274+ qo [ :first ] = true if options [ :fetch ] == :one
275+ qo [ :as ] = options [ :fetch ] == :rows ? :array : :hash
276+ end
277+ handle . each ( query_options )
278+ end
279+
256280 def handle_to_names_and_values_odbc ( handle , options = { } )
257281 @connection . use_utc = ActiveRecord ::Base . default_timezone == :utc if @connection_supports_native_types
258282 case options [ :fetch ]
@@ -351,6 +375,7 @@ def handle_to_names_and_values_adonet(handle, options={})
351375
352376 def finish_statement_handle ( handle )
353377 case @connection_options [ :mode ]
378+ when :dblib
354379 when :odbc
355380 handle . drop if handle && handle . respond_to? ( :drop ) && !handle . finished?
356381 when :adonet
0 commit comments