Skip to content

Commit

Permalink
PostgreSQLAdapter#select_raw fields and results are empty even if ntu…
Browse files Browse the repository at this point in the history
…ples is 0
  • Loading branch information
tenderlove committed Jul 13, 2010
1 parent c9710a4 commit 8521cdf
Showing 1 changed file with 21 additions and 25 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -949,34 +949,30 @@ def select(sql, name = nil)
def select_raw(sql, name = nil) def select_raw(sql, name = nil)
res = execute(sql, name) res = execute(sql, name)
results = result_as_array(res) results = result_as_array(res)
fields = [] fields = res.fields
rows = [] rows = results.map do |row|
if res.ntuples > 0 hashed_row = {}
fields = res.fields row.each_index do |cell_index|
results.each do |row| # If this is a money type column and there are any currency symbols,
hashed_row = {} # then strip them off. Indeed it would be prettier to do this in
row.each_index do |cell_index| # PostgreSQLColumn.string_to_decimal but would break form input
# If this is a money type column and there are any currency symbols, # fields that call value_before_type_cast.
# then strip them off. Indeed it would be prettier to do this in if res.ftype(cell_index) == MONEY_COLUMN_TYPE_OID
# PostgreSQLColumn.string_to_decimal but would break form input # Because money output is formatted according to the locale, there are two
# fields that call value_before_type_cast. # cases to consider (note the decimal separators):
if res.ftype(cell_index) == MONEY_COLUMN_TYPE_OID # (1) $12,345,678.12
# Because money output is formatted according to the locale, there are two # (2) $12.345.678,12
# cases to consider (note the decimal separators): case column = row[cell_index]
# (1) $12,345,678.12 when /^-?\D+[\d,]+\.\d{2}$/ # (1)
# (2) $12.345.678,12 row[cell_index] = column.gsub(/[^-\d\.]/, '')
case column = row[cell_index] when /^-?\D+[\d\.]+,\d{2}$/ # (2)
when /^-?\D+[\d,]+\.\d{2}$/ # (1) row[cell_index] = column.gsub(/[^-\d,]/, '').sub(/,/, '.')
row[cell_index] = column.gsub(/[^-\d\.]/, '')
when /^-?\D+[\d\.]+,\d{2}$/ # (2)
row[cell_index] = column.gsub(/[^-\d,]/, '').sub(/,/, '.')
end
end end

hashed_row[fields[cell_index]] = column
end end
rows << row
hashed_row[fields[cell_index]] = column
end end
row
end end
res.clear res.clear
return fields, rows return fields, rows
Expand Down

0 comments on commit 8521cdf

Please sign in to comment.