Skip to content

Commit

Permalink
timestamp fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amirtuval committed Sep 1, 2016
1 parent 3808929 commit c3f5544
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/vertica/protocol/frontend/bind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def convert_to_string(val, parameter_type)
return '1' if parameter_type.name == 'bool' and TrueClass === val
return '0' if parameter_type.name == 'bool' and FalseClass === val

return val.strftime('%Y-%m-%d %H:%M:%S.%6N %z') if Time === val

val.to_s
end
end
Expand Down
12 changes: 10 additions & 2 deletions test/functional/functional_prepared_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_incorrect_parameters

def test_parameter_types
today = Date.today
now = Time.now.round
now = Time.now.round(6)
binary_data = ['d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21'].pack('H*')
decimal = BigDecimal.new('1.12')

Expand All @@ -128,17 +128,25 @@ def test_parameter_types
assert_equal 'hello ', row[:char_field]
assert_equal 'hello world', row[:long_varchar_field]
assert_equal today, row[:date_field]

assert_equal now, row[:timestamp_field]
assert_equal now, row[:timestamptz_field]
assert_equal false, row[:boolean_field]
assert_equal -1.123, row[:float_field]
assert_equal decimal, row[:numeric_field]
assert_equal binary_data, row[:binary_field]

r = @connection.query("select TO_CHAR(timestamp_field, 'YYYY-MM-DD HH24:MI:SS.MS') as timestamp_str, TO_CHAR(timestamptz_field, 'YYYY-MM-DD HH24:MI:SS.MS TZ') as timestamptz_str from pq_conversions_table where int_field = 123")

assert_equal 1, r.size
row = r[0]
assert_equal now.strftime('%Y-%m-%d %H:%M:%S.%L'), row[:timestamp_str]
assert_equal now.strftime('%Y-%m-%d %H:%M:%S.%L %Z'), row[:timestamptz_str]
end

def test_parameter_types_condition
today = Date.today
now = Time.now.round
now = Time.now
binary_data = ['d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21'].pack('H*')
decimal = BigDecimal.new('1.12')

Expand Down

0 comments on commit c3f5544

Please sign in to comment.