Permalink
Browse files

Fix typecasting of time columns on jdbc/postgres, before could be off…

… by a millisecond

I was getting this occassional failure on the jdbc/postgres tests,
which I tracked down to the floating point addition done here.
Instead of doing floating point addition after time parsing, put
the correct milliseconds as part of the string, so that the time
parsing code can get it correct without the need to worry about
rational numbers.
  • Loading branch information...
1 parent d2435d8 commit 7c01d002e7746640fcf408681160c1ca783b9e65 @jeremyevans committed May 30, 2012
Showing with 3 additions and 1 deletion.
  1. +2 −0 CHANGELOG
  2. +1 −1 lib/sequel/adapters/jdbc.rb
View
@@ -1,5 +1,7 @@
=== HEAD
+* Fix typecasting of time columns on jdbc/postgres, before could be off by a millisecond (jeremyevans)
+
* Add document explaining Sequel's object model (jeremyevans)
* Attempt to detect more disconnect errors in the mysql2 adapter (jeremyevans)
@@ -640,7 +640,7 @@ def prepare(type, name=nil, *values)
# Handle type conversions for common Java types.
class TYPE_TRANSLATOR
LF = "\n".freeze
- def time(v) Sequel.string_to_time(v.to_string) + v.getTime.divmod(1000).last/1000.0 end
+ def time(v) Sequel.string_to_time("#{v.to_string}.#{sprintf('%03i', v.getTime.divmod(1000).last)}") end
def date(v) Date.civil(v.getYear + 1900, v.getMonth + 1, v.getDate) end
def decimal(v) BigDecimal.new(v.to_string) end
def byte_array(v) Sequel::SQL::Blob.new(String.from_java_bytes(v)) end

0 comments on commit 7c01d00

Please sign in to comment.