Skip to content

Commit 58cddae

Browse files
committed
Make sure that returned string values are being tagged as UTF-8 instead of binary in Ruby 1.9
1 parent f0d2954 commit 58cddae

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/vertica/column.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class Column
66
attr_reader :size
77
attr_reader :data_type
88

9+
STRING_CONVERTER = String.new.respond_to?(:force_encoding) ? lambda { |s| s.force_encoding('utf-8') } : nil
10+
911
DATA_TYPE_CONVERSIONS = [
1012
[:unspecified, nil],
1113
[:tuple, nil],
@@ -15,8 +17,8 @@ class Column
1517
[:bool, lambda { |s| s == 't' }],
1618
[:integer, lambda { |s| s.to_i }],
1719
[:float, lambda { |s| s.to_f }],
18-
[:char, nil],
19-
[:varchar, nil],
20+
[:char, STRING_CONVERTER],
21+
[:varchar, STRING_CONVERTER],
2022
[:date, lambda { |s| Date.new(*s.split("-").map{|x| x.to_i}) }],
2123
[:time, nil],
2224
[:timestamp, lambda { |s| DateTime.parse(s, true) }],

test/functional/value_conversion_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# encoding : UTF-8
12
require 'test_helper'
23

34
class ValueConversionTest < Test::Unit::TestCase
@@ -44,4 +45,8 @@ def test_nil_conversions
4445
assert_equal result.rows.length, 1
4546
assert_equal [nil, nil, nil, nil, nil, nil, nil], result.rows.first
4647
end
48+
49+
def test_string_encoding
50+
assert_equal 'åßç∂ë', @connection.query("SELECT 'åßç∂ë'").the_value
51+
end
4752
end

0 commit comments

Comments
 (0)