aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-12 17:44:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-12 17:44:15 -0700
commit8521cdf03d2b9761f21b593e10a31ca96d05092c (patch)
tree28ea746fef9d61df4beb32508e108eb7c0a450e2
parentc9710a43ff6cdc536f08983b007768ae6a66dd10 (diff)
downloadrails-8521cdf03d2b9761f21b593e10a31ca96d05092c.tar.gz
rails-8521cdf03d2b9761f21b593e10a31ca96d05092c.tar.bz2
rails-8521cdf03d2b9761f21b593e10a31ca96d05092c.zip
PostgreSQLAdapter#select_raw fields and results are empty even if ntuples is 0
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb46
1 files changed, 21 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 9bf08a7671..1429f44ff3 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -949,34 +949,30 @@ module ActiveRecord
def select_raw(sql, name = nil)
res = execute(sql, name)
results = result_as_array(res)
- fields = []
- rows = []
- if res.ntuples > 0
- fields = res.fields
- results.each do |row|
- hashed_row = {}
- row.each_index do |cell_index|
- # If this is a money type column and there are any currency symbols,
- # then strip them off. Indeed it would be prettier to do this in
- # PostgreSQLColumn.string_to_decimal but would break form input
- # fields that call value_before_type_cast.
- if res.ftype(cell_index) == MONEY_COLUMN_TYPE_OID
- # Because money output is formatted according to the locale, there are two
- # cases to consider (note the decimal separators):
- # (1) $12,345,678.12
- # (2) $12.345.678,12
- case column = row[cell_index]
- when /^-?\D+[\d,]+\.\d{2}$/ # (1)
- row[cell_index] = column.gsub(/[^-\d\.]/, '')
- when /^-?\D+[\d\.]+,\d{2}$/ # (2)
- row[cell_index] = column.gsub(/[^-\d,]/, '').sub(/,/, '.')
- end
+ fields = res.fields
+ rows = results.map do |row|
+ hashed_row = {}
+ row.each_index do |cell_index|
+ # If this is a money type column and there are any currency symbols,
+ # then strip them off. Indeed it would be prettier to do this in
+ # PostgreSQLColumn.string_to_decimal but would break form input
+ # fields that call value_before_type_cast.
+ if res.ftype(cell_index) == MONEY_COLUMN_TYPE_OID
+ # Because money output is formatted according to the locale, there are two
+ # cases to consider (note the decimal separators):
+ # (1) $12,345,678.12
+ # (2) $12.345.678,12
+ case column = row[cell_index]
+ when /^-?\D+[\d,]+\.\d{2}$/ # (1)
+ row[cell_index] = column.gsub(/[^-\d\.]/, '')
+ when /^-?\D+[\d\.]+,\d{2}$/ # (2)
+ row[cell_index] = column.gsub(/[^-\d,]/, '').sub(/,/, '.')
end
-
- hashed_row[fields[cell_index]] = column
end
- rows << row
+
+ hashed_row[fields[cell_index]] = column
end
+ row
end
res.clear
return fields, rows