mneumann / postgres-pr

A pure-Ruby (pr) library for accessing PostgreSQL databases
http://rubyforge.org/projects/postgres-pr
43 stars 13 forks source link

Returns all strings encoded as US_ASCII? #7

Open andy-twosticks opened 8 years ago

andy-twosticks commented 8 years ago

I get this behaviour when connected to a database encoded as UTF-8.

Example Code:

require 'postgres-pr/connection'
c = PostgresPR::Connection.new('blah', 'blah', 'blah')

row = c.query("select name, cost from remedium.prescription").rows.last
row.each do |f|
  #f.force_encoding(Encoding::UTF_8) #-- uncomment this to 'fix' everything ;/

  enc = f.kind_of?(String) ? f.encoding : ''
  puts [f.class, f, f.inspect, enc].join(' ')
end

Output:

String Paracelsium "Paracelsium" ASCII-8BIT
String £0.00 "\xC2\xA30.00" ASCII-8BIT

I don't know what you can do to resolve this -- but other adapters don't appear to have this problem, so I suppose it must be technically possible to resolve it. [Ruby 2.3; Postgres 9.2]