aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-13 10:57:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-13 10:57:22 -0700
commit35e304193b8513e1da523a9c1c34bf323e52b9e6 (patch)
treef406ebbae10de3d7c049331c98f934fe13cc05bc
parentbc35631dc7d67ec9c918ec1967c708a5388a76e4 (diff)
downloadrails-35e304193b8513e1da523a9c1c34bf323e52b9e6.tar.gz
rails-35e304193b8513e1da523a9c1c34bf323e52b9e6.tar.bz2
rails-35e304193b8513e1da523a9c1c34bf323e52b9e6.zip
only loop through all rows and columns once in the postgres adapter
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb46
1 files changed, 23 insertions, 23 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 4baf99610e..d773be0ca6 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -432,8 +432,7 @@ module ActiveRecord
# check if we have any binary column and if they need escaping
unescape_col = []
res.nfields.times do |j|
- # unescape string passed BYTEA field (OID == 17)
- unescape_col << ( res.ftype(j) == BYTEA_COLUMN_TYPE_OID )
+ unescape_col << res.ftype(j)
end
ary = []
@@ -441,7 +440,28 @@ module ActiveRecord
ary << []
res.nfields.times do |j|
data = res.getvalue(i,j)
- data = unescape_bytea(data) if unescape_col[j] and data.is_a?(String)
+ case unescape_col[j]
+
+ # unescape string passed BYTEA field (OID == 17)
+ when BYTEA_COLUMN_TYPE_OID
+ data = unescape_bytea(data) if String === data
+
+ # 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.
+ when 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 data
+ when /^-?\D+[\d,]+\.\d{2}$/ # (1)
+ data.gsub!(/[^-\d\.]/, '')
+ when /^-?\D+[\d\.]+,\d{2}$/ # (2)
+ data.gsub!(/[^-\d,]/, '').sub!(/,/, '.')
+ end
+ end
ary[i] << data
end
end
@@ -952,26 +972,6 @@ module ActiveRecord
res = execute(sql, name)
results = result_as_array(res)
fields = res.fields
- results.each do |row|
- row.each_with_index do |cell, 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 cell
- when /^-?\D+[\d,]+\.\d{2}$/ # (1)
- cell.gsub!(/[^-\d\.]/, '')
- when /^-?\D+[\d\.]+,\d{2}$/ # (2)
- cell.gsub!(/[^-\d,]/, '').sub!(/,/, '.')
- end
- end
- end
- end
res.clear
return fields, results
end