Skip to content

Commit

Permalink
Fix :time typecasting from Time to SQLTime for fractional seconds on …
Browse files Browse the repository at this point in the history
…ruby 1.9

Thanks to John Anderson for pointing out this problem.
  • Loading branch information
jeremyevans committed Sep 18, 2011
1 parent 7ccb650 commit 88a9321
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD

* Fix :time typecasting from Time to SQLTime for fractional seconds on ruby 1.9 (jeremyevans)

* Have Dataset#select_append check supports_select_all_and_column? and select all from all FROM and JOIN tables if no columns selected (jeremyevans)

* Add Dataset#supports_select_all_and_column? for checking if you can do SELECT *, column (jeremyevans)
Expand Down
2 changes: 1 addition & 1 deletion lib/sequel/database/misc.rb
Expand Up @@ -278,7 +278,7 @@ def typecast_value_time(value)
when SQLTime
value
when Time
SQLTime.local(value.year, value.month, value.day, value.hour, value.min, value.sec, value.respond_to?(:nsec) ? value.nsec : value.usec)
SQLTime.local(value.year, value.month, value.day, value.hour, value.min, value.sec, value.respond_to?(:nsec) ? value.nsec/1000.0 : value.usec)
when String
Sequel.string_to_time(value)
when Hash
Expand Down
7 changes: 7 additions & 0 deletions spec/core/database_spec.rb
Expand Up @@ -1544,6 +1544,13 @@ def @db.disconnect_connection(c)
end
end

specify "should correctly handle time value conversion to SQLTime with fractional seconds" do
t = Time.now
st = Sequel::SQLTime.local(t.year, t.month, t.day, 1, 2, 3, 500000)
t = Time.local(t.year, t.month, t.day, 1, 2, 3, 500000)
@db.typecast_value(:time, t).should == st
end

specify "should have an underlying exception class available at wrapped_exception" do
begin
@db.typecast_value(:date, 'a')
Expand Down

0 comments on commit 88a9321

Please sign in to comment.