Skip to content

Commit

Permalink
Refactored select routing for SQL Server adapter (closes #5683) [tom@…
Browse files Browse the repository at this point in the history
…popdog.net]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4671 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Aug 5, 2006
1 parent c99df46 commit 5779deb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -504,22 +504,22 @@ def remove_index(table_name, options = {})


private private
def select(sql, name = nil) def select(sql, name = nil)
rows = []
repair_special_columns(sql) repair_special_columns(sql)
log(sql, name) do
@connection.select_all(sql) do |row| result = []
record = {} execute(sql) do |handle|
row.column_names.each do |col| handle.each do |row|
record[col] = row[col] row_hash = {}
if record[col].is_a? DBI::Timestamp row.each_with_index do |value, i|
ts = record[col] if value.is_a? DBI::Timestamp
record[col] = DateTime.new(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.sec) value = DateTime.new(value.year, value.month, value.day, value.hour, value.minute, value.sec)
end end
row_hash[handle.column_names[i]] = value
end end
rows << record result << row_hash
end end
end end
rows result
end end


# Turns IDENTITY_INSERT ON for table during execution of the block # Turns IDENTITY_INSERT ON for table during execution of the block
Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/abstract_unit.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def current_adapter?(*types)
cattr_accessor :query_count cattr_accessor :query_count


# Array of regexes of queries that are not counted against query_count # Array of regexes of queries that are not counted against query_count
@@ignore_list = [/^SELECT currval/, /^SELECT CAST/] @@ignore_list = [/^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/]


alias_method :execute_without_query_counting, :execute alias_method :execute_without_query_counting, :execute
def execute_with_query_counting(sql, name = nil) def execute_with_query_counting(sql, name = nil, &block)
self.query_count += 1 unless @@ignore_list.any? { |r| sql =~ r } self.query_count += 1 unless @@ignore_list.any? { |r| sql =~ r }
execute_without_query_counting(sql, name) execute_without_query_counting(sql, name, &block)
end end
end end


Expand Down

0 comments on commit 5779deb

Please sign in to comment.